com.actelion.research.chem.SSSearcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openchemlib Show documentation
Show all versions of openchemlib Show documentation
Open Source Chemistry Library
/*
* Copyright (c) 1997 - 2016
* Actelion Pharmaceuticals Ltd.
* Gewerbestrasse 16
* CH-4123 Allschwil, Switzerland
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package com.actelion.research.chem;
import com.actelion.research.util.IntArrayComparator;
import java.util.*;
public class SSSearcher {
// CONSTANTS TO DEFINE KIND OF SIMILARITY BETWEEN ATOMS AND BONDS
public final static int cMatchAtomCharge = 1;
public final static int cMatchAtomMass = 2;
public final static int cMatchDBondToDelocalized = 4;
public final static int cMatchAromDBondToDelocalized = 8;
/* For index match modes we need to consider the following:
- If fragment C is SS of fragment B and B is SS of molecule A then C must be SS of A.
This implies that if X is SS of Y then X is in all respects equal or less exactly
defined as Y. Consequently, if the SS operator matches any double bonds to aromatic
double bonds and matches aromatic double bonds to delocaliced bonds, it must match
any double bond to delocalized bonds (cMatchAromDBondToDelocalized cannot be used for
index creation). Example: key C=C-N-C=C, query pyrol, molecule indole, key would match
pyrol but not indol!!!
- match modes used for the actual atom by atom check must be more or equally restrictive
than the match mode used for index creation. Otherwise index keys may filter out
molecules which would be considered a match with the less strict matching consitions
of the atom by atom check.
*/
// match mode to be used for index creation
public static final int cIndexMatchMode = cMatchDBondToDelocalized;
public static final int cDefaultMatchMode = cMatchAromDBondToDelocalized;
public final static int cCountModeExistance = 1;
public final static int cCountModeFirstMatch = 2;
public final static int cCountModeOverlapping = 3;
public final static int cCountModeRigorous = 4;
// default behaviour for unusual atom masses and atom charges is that
// - if no atom charge/mass is specified in the query then all charges/masses match
// - if an atom charge/mass is specified then this charge/mass must match for the atom to match
// defines details of similarity between atoms and bonds
private int mDefaultMatchMode;
// The molecule which is analyzed
protected StereoMolecule mMolecule;
// The sub-structure we try to find in the molecule
protected StereoMolecule mFragment;
private int[] mMoleculeAtomType; // atom features required to match
private int[] mFragmentAtomType;
private int[] mMoleculeAtomFeatures; // flags defining given/required atom features
private int[] mFragmentAtomFeatures;
private int[] mMoleculeBondFeatures; // flags defining given/required bond features
private int[] mFragmentBondFeatures;
private int mFragmentExcludeAtoms,mFragmentExcludeBonds;
private int mFragmentGraphSize; // the number of wanted atoms & ring closures in fragment graph
private int mFragmentGraphSizeWithExcludeGroup; // total number of atoms & ring closures in fragment graph
private int[] mFragmentGraphAtom;
private int[] mFragmentGraphParentAtom;
private int[] mFragmentGraphParentBond;
private boolean[] mFragmentGraphIsRingClosure;
private boolean[] mIsExcludeAtom;
private int[] mFragmentConnAtoms; // in case of exclude atoms, these are not part of this
private int[] mMatchTable;
// depending on the fragment count mode this may contain atom lists
// of all till now located matching sub-fragments
private TreeSet mSortedMatchSet,mExcludedMatchSet;
private ArrayList mMatchList;
private ArrayList mBridgeBondList;
private boolean mMoleculeFeaturesValid;
private boolean mFragmentFeaturesValid;
private int mRequiredHelperLevel;
/**
* Instantiates a SSSearcher object for running sub-structure searches
* with one or more sub-structure fragments on one or more molecules.
* The search is a pure graph matching algorithm.
* For fast sub-structure searches involving an index based pre-screening use the class SSSearcherWithIndex.
* For a more high-level structure search supporting multiple cores, sub-structure-, similarity-,
* exact-, or tautomer-search use class StructureSearch and related classes.
*/
public SSSearcher() {
mDefaultMatchMode = cDefaultMatchMode;
mMatchList = new ArrayList();
mSortedMatchSet = new TreeSet(new IntArrayComparator());
mExcludedMatchSet = new TreeSet(new IntArrayComparator());
}
/**
* Instantiates a SSSearcher object for running sub-structure searches
* with one or more sub-structure fragments on one or more molecules.
* The search is a pure graph matching algorithm.
* For fast sub-structure searches involving an index based pre-screening use the class SSSearcherWithIndex.
* For a more high-level structure search supporting multiple cores, sub-structure-, similarity-,
* exact-, or tautomer-search use class StructureSearch and related classes.
* @param matchMode combination of cMatchAtomCharge, cMatchAtomMass, cMatchDBondToDelocalized, cMatchAromDBondToDelocalized
*/
public SSSearcher(int matchMode) {
mDefaultMatchMode = matchMode;
mMatchList = new ArrayList();
mSortedMatchSet = new TreeSet(new IntArrayComparator());
mExcludedMatchSet = new TreeSet(new IntArrayComparator());
}
/**
* Defines fragment and molecule before calling isFragmentInMolecule(...)
* or findFragmentInMolecule(...).
* @param fragment
* @param molecule
*/
public void setMol(StereoMolecule fragment, StereoMolecule molecule) {
setMolecule(molecule);
setFragment(fragment);
}
/**
* Defines the molecule to be used in isFragmentInMolecule(...)
* or findFragmentInMolecule(...).
* @param molecule
*/
public void setMolecule(StereoMolecule molecule) {
if (molecule.getAllAtoms() == 0) {
mMolecule = null;
return;
}
mMolecule = molecule;
mMoleculeFeaturesValid = false;
mMolecule.ensureHelperArrays(Molecule.cHelperNeighbours);
}
/**
* Defines the fragment to be used in isFragmentInMolecule(...)
* or findFragmentInMolecule(...).
* @param fragment
*/
public void setFragment(StereoMolecule fragment) {
if (fragment.getAllAtoms() == 0 || !fragment.isFragment()) {
mFragment = null;
return;
}
mFragment = fragment;
mFragmentFeaturesValid = false;
mFragment.ensureHelperArrays(Molecule.cHelperNeighbours);
mRequiredHelperLevel = Molecule.cHelperRings;
for (int atom=0; atom
* - it is not equal to the parent of the current graph atom and
* - if the bond to the candidate is not a bridge bond
* - if the bond was not added to the graph already
* then attach the candidate to the graph and mark, whether it is a ring closure (and therefore duplicate).
* @param current
* @param highest
* @param i connAtom index of current graph atom
* @param fragmentAtomUsed
* @param fragmentBondUsed
* @return
*/
private int tryAddCandidate(int current, int highest, int i, boolean[] fragmentAtomUsed, boolean[] fragmentBondUsed) {
int candidate = mFragment.getConnAtom(mFragmentGraphAtom[current], i);
if (candidate != mFragmentGraphParentAtom[current]) {
int candidateBond = mFragment.getConnBond(mFragmentGraphAtom[current], i);
if (!fragmentBondUsed[candidateBond] // if it is a ring closure make sure it is added only once
&& !mFragment.isBondBridge(candidateBond)) { // don't consider bridge bonds at this state
mFragmentGraphAtom[++highest] = candidate;
mFragmentGraphParentAtom[highest] = mFragmentGraphAtom[current];
mFragmentGraphParentBond[highest] = candidateBond;
fragmentBondUsed[candidateBond] = true;
if (fragmentAtomUsed[candidate])
mFragmentGraphIsRingClosure[highest] = true;
else
fragmentAtomUsed[candidate] = true;
}
}
return highest;
}
/**
* If the match count mode is one of cCountModeFirstMatch, cCountModeOverlapping,
* cCountModeRigorous then this method returns an arraylist of all counted matches,
* i.e. int arrays mapping fragment atoms to molecule atoms. Atoms being part of a
* matched bridge bond are naturally not covered by the mapping.
* Note: If some query fragment atoms are marked as exclude group, then the respective
* matchlist values are -1.
* @return list of distinct counted matches.
*/
public ArrayList getMatchList() {
return mMatchList;
}
/**
* Fastest check, whether the molecule contains the fragment.
* This method uses cCountModeExistance and therefore does not create
* any retrievable match list, i.e. mapping from fragment atoms to molecule atoms.
* The match mode used is cDefaultMatchMode, unless defined otherwise when
* instantiating the SSSearcher.
* @return whether fragment was found as sub-structure in molecule
*/
public boolean isFragmentInMolecule() {
return (findFragmentInMolecule(cCountModeExistance, mDefaultMatchMode) > 0);
}
/**
* Fastest check, whether the molecule contains the fragment.
* This method uses cCountModeExistance and therefore does not create
* any retrievable match list, i.e. mapping from fragment atoms to molecule atoms.
* @param matchMode cDefaultMatchMode or combination of cMatchAtomCharge, cMatchAtomMass, cMatchDBondToDelocalized, cMatchAromDBondToDelocalized
* @return whether fragment was found as sub-structure in molecule
*/
public boolean isFragmentInMolecule(int matchMode) {
return (findFragmentInMolecule(cCountModeExistance, matchMode) > 0);
}
/**
* Locates all matches of the fragment in the molecule that result in distinguishable
* sets of molecule atoms. Multiple matches involving the same atoms, e.g. with a benzene ring,
* are counted and listed only once. Atom mapping from fragment to molecule
* is collected and can be retrieved with getMatchList().
* @return count of sub-structure matches of fragment in molecule
*/
public int findFragmentInMolecule() {
return findFragmentInMolecule(cCountModeOverlapping, mDefaultMatchMode);
}
/**
* Locates all matches of the fragment in the molecule that result in distinguishable
* sets of molecule atoms. Multiple matches involving the same atoms, e.g. with a benzene ring,
* are counted and listed only once. If count mode is different from cCountModeExistance,
* then an atom mapping from fragment to molecule is collected and can be retrieved with getMatchList().
* @param countMode one of cCountModeExistance, cCountModeFirstMatch, cCountModeOverlapping, cCountModeRigorous
* @param matchMode cDefaultMatchMode or combination of cMatchAtomCharge, cMatchAtomMass, cMatchDBondToDelocalized, cMatchAromDBondToDelocalized
* @return count of sub-structure matches of fragment in molecule
*/
public int findFragmentInMolecule(int countMode, int matchMode) {
return findFragmentInMolecule(countMode, matchMode, null);
}
/**
* Locates all matches of the fragment in the molecule that result in distinguishable
* sets of molecule atoms that are not flagged to be excluded from matching.
* Multiple matches involving the same atoms, e.g. with a benzene ring,
* are counted and listed only once. If count mode is different from cCountModeExistance,
* then an atom mapping from fragment to molecule is collected and can be retrieved with getMatchList().
* If the query fragment does not contain atoms other than exclude group atoms, then no match is returned.
* @param countMode one of cCountModeExistance, cCountModeFirstMatch, cCountModeOverlapping, cCountModeRigorous
* @param matchMode cDefaultMatchMode or combination of cMatchAtomCharge, cMatchAtomMass, cMatchDBondToDelocalized, cMatchAromDBondToDelocalized
* @param atomExcluded defines atoms of molecule to be excluded from sub-structure matching
* @return count of sub-structure matches of fragment in molecule
*/
public int findFragmentInMolecule(int countMode, int matchMode, final boolean[] atomExcluded) {
mMatchList = new ArrayList();
mSortedMatchSet.clear();
mExcludedMatchSet.clear();
if (mMolecule == null
|| mFragment == null)
return 0;
if (mFragment.getAtoms() - mFragmentExcludeAtoms > mMolecule.getAtoms()
|| mFragment.getBonds() - mFragmentExcludeBonds > mMolecule.getBonds())
return 0;
if (mFragment.getAtoms() - mFragmentExcludeAtoms == 0)
return 0;
/*
System.out.print(" molecule:"); for (int i=0; i comparator = new IntArrayComparator();
int[] tempMatch = new int[sortedMatch.length];
for (int i=mMatchList.size()-1; i>=0; i--) {
int[] match = mMatchList.get(i);
System.arraycopy(match, 0, tempMatch, 0, tempMatch.length);
Arrays.sort(tempMatch);
if (comparator.compare(tempMatch, sortedMatch) == 0)
mMatchList.remove(i);
}
isExcludedMatch = true;
}
}
if (!isExcludedMatch) {
addMatchIfQualifies(countMode);
if (countMode == cCountModeFirstMatch && mFragmentExcludeAtoms == 0)
return 1;
}
}
current--;
if (!mFragmentGraphIsRingClosure[current])
atomUsed[mMatchTable[mFragmentGraphAtom[current]]] = false;
}
}
return mMatchList.size();
}
private void addMatchIfQualifies(int countMode) {
int[] match = Arrays.copyOf(mMatchTable, mMatchTable.length);
if (countMode == cCountModeFirstMatch
|| countMode == cCountModeRigorous) {
// count every match (even permutations of same atoms)
mMatchList.add(match);
return;
}
if (mFragmentExcludeAtoms != 0 // store matches as indication that we have found something
|| countMode == cCountModeOverlapping) {
Arrays.sort(match);
if (!mSortedMatchSet.contains(match)) {
mSortedMatchSet.add(match);
mMatchList.add(Arrays.copyOf(mMatchTable, mMatchTable.length));
}
return;
}
// if (cCountModeSeparated) {
// not yet supported
// }
return;
}
protected boolean areAtomsSimilar(int moleculeAtom, int fragmentAtom) {
int moleculeConnAtoms = mMolecule.getConnAtoms(moleculeAtom);
int fragmentConnAtoms = mFragmentConnAtoms[fragmentAtom];
if (fragmentConnAtoms > moleculeConnAtoms)
return false;
/* In order to explicitly search and match attachment points (e.g. used by search substructure and replace)
* this behaviour was changed. TLS 29 Jan 2015
if (mFragment.getAtomicNo(fragmentAtom) == 0) // attachment points match on any atom
return true;
if (mMolecule.getAtomicNo(moleculeAtom) == 0) // real fragment atoms cannot match on attachment points in molecule
return false;
*/
int moleculeQF = mMolecule.getAtomQueryFeatures(moleculeAtom);
int fragmentQF = mFragment.getAtomQueryFeatures(fragmentAtom);
int[] fragmentList = mFragment.getAtomList(fragmentAtom);
int[] moleculeList = mMolecule.getAtomList(moleculeAtom);
// check atomicNo's considering all 16 combinations of: Any set or not, atom list given or not
if ((fragmentQF & Molecule.cAtomQFAny) != 0) {
if (fragmentList != null) {
if ((moleculeQF & Molecule.cAtomQFAny) != 0) {
if (moleculeList == null)
return false;
if (!isSubListOf(fragmentList, moleculeList))
return false;
}
else {
if (moleculeList != null) {
if (listsOverlap(moleculeList, fragmentList))
return false;
}
else {
if (isListMember(mMolecule.getAtomicNo(moleculeAtom), fragmentList))
return false;
}
}
}
} // 4 cases with Any set in fragment but no fragment exclude list given don't need to be checked
else {
// cAtomQFAny not set in fragment but Any set in molecule
if ((moleculeQF & Molecule.cAtomQFAny) != 0)
return false; // regardless of possibly given lists these 4 cases cannot match
// remaining cases: Any neither set in fragment nor molecule, but check for lists
if (fragmentList != null) {
if (moleculeList != null) {
if (!isSubListOf(moleculeList, fragmentList))
return false;
}
else {
if (!isListMember(mMolecule.getAtomicNo(moleculeAtom), fragmentList))
return false;
}
}
else {
if (moleculeList != null)
return false;
if (mMoleculeAtomType[moleculeAtom] != mFragmentAtomType[fragmentAtom])
return false;
}
} // end atomicNo, cAtomQFAny and AtomList checking
if ((moleculeQF | fragmentQF) != 0) {
if ((fragmentQF & Molecule.cAtomQFNoMoreNeighbours) != 0) {
if (mMolecule.isFragment()
&& (moleculeQF & Molecule.cAtomQFNoMoreNeighbours) == 0)
return false;
else if (fragmentConnAtoms != moleculeConnAtoms)
return false;
}
if ((fragmentQF & Molecule.cAtomQFMoreNeighbours) != 0) {
if ((fragmentConnAtoms >= moleculeConnAtoms)
&& (moleculeQF & Molecule.cAtomQFMoreNeighbours) == 0)
return false;
}
}
if ((mMoleculeAtomFeatures[moleculeAtom] & ~mFragmentAtomFeatures[fragmentAtom]) != 0)
return false;
if (mFragment.getAtomCharge(fragmentAtom) != 0
&& mFragment.getAtomCharge(fragmentAtom) != mMolecule.getAtomCharge(moleculeAtom))
return false;
if (mFragment.getAtomMass(fragmentAtom) != 0
&& mFragment.getAtomMass(fragmentAtom) != mMolecule.getAtomMass(moleculeAtom))
return false;
int ringSize = (mFragment.getAtomQueryFeatures(fragmentAtom) & Molecule.cAtomQFRingSize) >> Molecule.cAtomQFRingSizeShift;
if (ringSize != 0) {
if (mMolecule.isFragment()
&& ringSize == (mMolecule.getAtomQueryFeatures(fragmentAtom) & Molecule.cAtomQFRingSize) >> Molecule.cAtomQFRingSizeShift)
return true;
boolean found = false;
RingCollection ringSet = mMolecule.getRingSet();
for (int i=0; i mMatchTable[connAtom2])
^ (connAtom1 > connAtom2))
inversion = !inversion;
}
}
}
else { // allene parities
for (int i=0; i mMatchTable[neighbour[1]])
^(neighbour[0] > neighbour[1])))
inversion = !inversion;
}
}
return inversion;
}
/**
* Check whether all double bond parities required to match are compatible
* with a match.
* @return true if all E/Z parities match
*/
private boolean doEZParitiesMatch(boolean isExcludeGroup) {
for (int fragmentBond=0; fragmentBond mMatchTable[fragmentNeighbour[1]])
^ (fragmentNeighbour[0] > fragmentNeighbour[1]))
inversion = !inversion;
}
}
return inversion;
}
/**
* Starting from a full match of the fragment without exclude groups, this method
* continues the graph matching to find, whether the attached exclude group(s) can
* also be matched.
* @param atomUsed
* @return
*/
private boolean doExcludeGroupsMatch(boolean[] atomUsed, int[] index) {
for (int i=mFragmentGraphSize; i
* - Bridge bonds in the molecule are not matched to any fragment bond
* - Bridge bonds in the fragment are not considered in the graph-matching and
* checked after an otherwise successful match, whether the shortest path of
* unmatched atoms satisfies the min- and max-atom criteria.
* For fragment and(!) molecule containing bridge bonds we would need a more complex
* handling: - for every fragment bridge check all unmatched molecule paths and count
* for every path min- and max-lengths (considering all bridge bonds within path).
* Consider a match, if min- and max-atoms range fits into fragments bridge bond range.
* If we have multiple bridge bonds in fragment and partially overlapping bridge matches
* in the molecule, it would get very nasty...
* @param moleculeAtomUsed
* @return
*/
private boolean doBridgeBondsMatch(boolean[] moleculeAtomUsed, boolean isExcludeFragment) {
if (mBridgeBondList != null) {
for (BridgeBond bb:mBridgeBondList) {
if ((mIsExcludeAtom[bb.atom1] || mIsExcludeAtom[bb.atom2]) == isExcludeFragment) {
int bridgeSize = mMolecule.getPathLength(mMatchTable[bb.atom1], mMatchTable[bb.atom2], bb.maxBridgeSize+1, moleculeAtomUsed) - 1;
if (bridgeSize < bb.minBridgeSize
|| bridgeSize > bb.maxBridgeSize)
return false;
}
}
}
return true;
}
/**
* @param moleculeBond flag list of fragment bond features (features present)
* @param fragmentBond flag list of molecule bond features (features allowed)
* @return true if all molecule bond features are present in fragment bond
*/
protected boolean areBondsSimilar(int moleculeBond, int fragmentBond) {
if ((mMoleculeBondFeatures[moleculeBond] & ~mFragmentBondFeatures[fragmentBond]) != 0)
return false;
int ringSize = (mFragment.getBondQueryFeatures(fragmentBond) & Molecule.cBondQFRingSize) >> Molecule.cBondQFRingSizeShift;
if (ringSize != 0) {
if (mMolecule.isFragment()
&& ringSize == (mMolecule.getBondQueryFeatures(fragmentBond) & Molecule.cBondQFRingSize) >> Molecule.cBondQFRingSizeShift)
return true;
boolean found = false;
RingCollection ringSet = mMolecule.getRingSet();
for (int i=0; i atomicNo1)
return false;
}
return true;
}
private boolean listsOverlap(int[] list1, int[] list2) {
// returns true if both lists share at least one common member
int i1 = 0;
int i2 = 0;
while (i1 0)
queryDefaults |= (Molecule.cAtomQFNotCharge0 | Molecule.cAtomQFNotChargeNeg);
int hydrogens = mol.getAllHydrogens(atom);
switch (hydrogens) {
case 0:
queryDefaults |= (Molecule.cAtomQFHydrogen & ~Molecule.cAtomQFNot0Hydrogen);
break;
case 1:
queryDefaults |= (Molecule.cAtomQFHydrogen & ~Molecule.cAtomQFNot1Hydrogen);
break;
case 2:
queryDefaults |= (Molecule.cAtomQFHydrogen & ~Molecule.cAtomQFNot2Hydrogen);
break;
default:
queryDefaults |= (Molecule.cAtomQFHydrogen & ~Molecule.cAtomQFNot3Hydrogen);
break;
}
int neighbours = mol.getConnAtoms(atom);
switch (neighbours) {
case 0:
queryDefaults |= (Molecule.cAtomQFNeighbours & ~Molecule.cAtomQFNot0Neighbours);
break;
case 1:
queryDefaults |= (Molecule.cAtomQFNeighbours & ~Molecule.cAtomQFNot1Neighbour);
break;
case 2:
queryDefaults |= (Molecule.cAtomQFNeighbours & ~Molecule.cAtomQFNot2Neighbours);
break;
case 3:
queryDefaults |= (Molecule.cAtomQFNeighbours & ~Molecule.cAtomQFNot3Neighbours);
break;
default:
queryDefaults |= (Molecule.cAtomQFNeighbours & ~Molecule.cAtomQFNot4Neighbours);
break;
}
int piElectrons = mol.getAtomPi(atom);
switch (piElectrons) {
case 0:
queryDefaults |= (Molecule.cAtomQFNot1PiElectron
| Molecule.cAtomQFNot2PiElectrons);
break;
case 1:
queryDefaults |= (Molecule.cAtomQFNot0PiElectrons
| Molecule.cAtomQFNot2PiElectrons);
break;
default:
queryDefaults |= (Molecule.cAtomQFNot0PiElectrons
| Molecule.cAtomQFNot1PiElectron);
break;
}
}
else { // The fragments implicit features are not really necessary,
// but may speed up the graph matching.
if (mol.isAromaticAtom(atom))
queryDefaults |= Molecule.cAtomQFAromatic;
int ringBonds = mol.getAtomRingBondCount(atom);
if (ringBonds != 0) {
queryDefaults |= Molecule.cAtomQFNotChain;
if (ringBonds > 2)
queryDefaults |= Molecule.cAtomQFNot2RingBonds;
if (ringBonds > 3)
queryDefaults |= Molecule.cAtomQFNot3RingBonds;
}
int charge = mol.getAtomCharge(atom);
if (charge < 0)
queryDefaults |= (Molecule.cAtomQFNotCharge0 | Molecule.cAtomQFNotChargePos);
else if (charge > 0)
queryDefaults |= (Molecule.cAtomQFNotCharge0 | Molecule.cAtomQFNotChargeNeg);
// fragment atoms with n neighbours must have
// at least n neighbours in a matching molecule
int neighbours = mol.getConnAtoms(atom);
switch (neighbours) {
case 0:
break;
case 1:
queryDefaults |= (Molecule.cAtomQFNot0Neighbours);
break;
case 2:
queryDefaults |= (Molecule.cAtomQFNot0Neighbours | Molecule.cAtomQFNot1Neighbour);
break;
case 3:
queryDefaults |= (Molecule.cAtomQFNot0Neighbours | Molecule.cAtomQFNot1Neighbour | Molecule.cAtomQFNot2Neighbours);
break;
default:
queryDefaults |= (Molecule.cAtomQFNeighbours & ~Molecule.cAtomQFNot4Neighbours);
break;
}
}
int piElectrons = mol.getAtomPi(atom);
if (piElectrons > 0)
queryDefaults |= Molecule.cAtomQFNot0PiElectrons;
if (piElectrons > 1)
queryDefaults |= Molecule.cAtomQFNot1PiElectron;
return queryDefaults;
}
/**
* Generates inherent feature flags of a given bond.
* @param mol molecule or fragment of the SSS
* @param bond the bond of which to generate feature flags
* @return bond features independent of query features
*/
private int getBondQueryDefaults(StereoMolecule mol, int bond) {
int queryDefaults = 0;
if (mol.isDelocalizedBond(bond)
|| mol.getBondType(bond) == Molecule.cBondTypeDelocalized)
queryDefaults |= Molecule.cBondQFDelocalized;
else switch (mol.getBondOrder(bond)) {
case 1:
queryDefaults |= Molecule.cBondQFSingle;
break;
case 2:
queryDefaults |= Molecule.cBondQFDouble;
break;
case 3:
queryDefaults |= Molecule.cBondQFTriple;
break;
}
if (mol.isRingBond(bond))
queryDefaults |= Molecule.cBondQFRing;
else if (!mol.isFragment())
queryDefaults |= Molecule.cBondQFNotRing;
if (mol.isAromaticBond(bond))
queryDefaults |= Molecule.cBondQFAromatic;
else if (!mol.isFragment())
queryDefaults |= Molecule.cBondQFNotAromatic;
return queryDefaults;
}
private void buildBridgeBondList() {
mBridgeBondList = null;
for (int bond=0; bond();
BridgeBond bridgeBond = new BridgeBond();
bridgeBond.atom1 = mFragment.getBondAtom(0, bond);
bridgeBond.atom2 = mFragment.getBondAtom(1, bond);
bridgeBond.minBridgeSize = mFragment.getBondBridgeMinSize(bond);
bridgeBond.maxBridgeSize = mFragment.getBondBridgeMaxSize(bond);
mBridgeBondList.add(bridgeBond);
}
}
}
private class BridgeBond {
int atom1,atom2,minBridgeSize,maxBridgeSize;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy