Skip to content

Commit

Permalink
removed explicit query feature bond types for the sake of simplicity.…
Browse files Browse the repository at this point in the history
… Now regular bond types are used instead also for defining multiple alloweedd bonds as query features.
  • Loading branch information
thsa committed Dec 20, 2024
1 parent 21615c2 commit 3f2b0b2
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 133 deletions.
18 changes: 9 additions & 9 deletions src/main/java/com/actelion/research/chem/ExtendedMolecule.java
Original file line number Diff line number Diff line change
Expand Up @@ -4151,8 +4151,8 @@ public void validateBondQueryFeatures() {
for (int bond=0; bond<mBonds; bond++) {
int bondTypeQFCount = Integer.bitCount(mBondQueryFeatures[bond] & (Molecule.cBondQFBondTypes | Molecule.cBondQFRareBondTypes));

if (isDelocalizedBond(bond) & (mBondQueryFeatures[bond] & cBondQFDelocalized) != 0) {
mBondQueryFeatures[bond] &= ~cBondQFDelocalized;
if (isDelocalizedBond(bond) & (mBondQueryFeatures[bond] & cBondTypeDelocalized) != 0) {
mBondQueryFeatures[bond] &= ~cBondTypeDelocalized;
bondTypeQFCount--;
}

Expand All @@ -4161,19 +4161,19 @@ public void validateBondQueryFeatures() {
if (bondTypeQFCount != 0) {
int bondType = mBondType[bond] & cBondTypeMaskSimple;
if (bondType == cBondTypeSingle)
mBondQueryFeatures[bond] |= cBondQFSingle;
mBondQueryFeatures[bond] |= cBondTypeSingle;
else if (bondType == cBondTypeDouble)
mBondQueryFeatures[bond] |= cBondQFDouble;
mBondQueryFeatures[bond] |= cBondTypeDouble;
else if (bondType == cBondTypeTriple)
mBondQueryFeatures[bond] |= cBondQFTriple;
mBondQueryFeatures[bond] |= cBondTypeTriple;
else if (bondType == cBondTypeQuadruple)
mBondQueryFeatures[bond] |= cBondQFQuadruple;
mBondQueryFeatures[bond] |= cBondTypeQuadruple;
else if (bondType == cBondTypeQuintuple)
mBondQueryFeatures[bond] |= cBondQFQuintuple;
mBondQueryFeatures[bond] |= cBondTypeQuintuple;
else if (bondType == cBondTypeMetalLigand)
mBondQueryFeatures[bond] |= cBondQFMetalLigand;
mBondQueryFeatures[bond] |= cBondTypeMetalLigand;
else if (bondType == cBondTypeDelocalized)
mBondQueryFeatures[bond] |= cBondQFDelocalized;
mBondQueryFeatures[bond] |= cBondTypeDelocalized;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -925,31 +925,31 @@ private void fixMultipleBondTypes() {
int bondType = -1;
int selectionCount = 0;

if ((queryFeatures & Molecule.cBondQFMetalLigand) != 0) {
if ((queryFeatures & Molecule.cBondTypeMetalLigand) != 0) {
bondType = Molecule.cBondTypeMetalLigand;
selectionCount++;
}
if ((queryFeatures & Molecule.cBondQFQuintuple) != 0) {
if ((queryFeatures & Molecule.cBondTypeQuintuple) != 0) {
bondType = Molecule.cBondTypeQuintuple;
selectionCount++;
}
if ((queryFeatures & Molecule.cBondQFQuadruple) != 0) {
if ((queryFeatures & Molecule.cBondTypeQuadruple) != 0) {
bondType = Molecule.cBondTypeQuadruple;
selectionCount++;
}
if ((queryFeatures & Molecule.cBondQFTriple) != 0) {
if ((queryFeatures & Molecule.cBondTypeTriple) != 0) {
bondType = Molecule.cBondTypeTriple;
selectionCount++;
}
if ((queryFeatures & Molecule.cBondQFDouble) != 0) {
if ((queryFeatures & Molecule.cBondTypeDouble) != 0) {
bondType = Molecule.cBondTypeDouble;
selectionCount++;
}
if ((queryFeatures & Molecule.cBondQFDelocalized) != 0) {
if ((queryFeatures & Molecule.cBondTypeDelocalized) != 0) {
bondType = Molecule.cBondTypeDelocalized;
selectionCount++;
}
if ((queryFeatures & Molecule.cBondQFSingle) != 0) {
if ((queryFeatures & Molecule.cBondTypeSingle) != 0) {
bondType = Molecule.cBondTypeSingle;
selectionCount++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,37 +820,37 @@ private void appendBondOrderSymbol(int bond, int parentAtom, StringBuilder build
if (mEZHalfParity[bond] != 0)
builder.append(mEZHalfParity[bond] == 1 ? '/' : '\\');
if (mMode == MODE_CREATE_SMARTS) {
int bondTypes = mMol.getBondQueryFeatures(bond) & (Molecule.cBondQFBondTypes | Molecule.cBondQFRareBondTypes);
if (bondTypes != 0) {
if ((bondTypes & Molecule.cBondTypeSingle) != 0 && mEZHalfParity[bond] == 0) {
int bondQFTypes = mMol.getBondQueryFeatures(bond) & (Molecule.cBondQFBondTypes | Molecule.cBondQFRareBondTypes);
if (bondQFTypes != 0) {
if ((bondQFTypes & Molecule.cBondTypeSingle) != 0 && mEZHalfParity[bond] == 0) {
builder.append('-');
}
if ((bondTypes & Molecule.cBondTypeDouble) != 0) {
if ((bondQFTypes & Molecule.cBondTypeDouble) != 0) {
if (builder.length() != startLength)
builder.append(',');
builder.append('=');
}
if ((bondTypes & Molecule.cBondTypeTriple) != 0) {
if ((bondQFTypes & Molecule.cBondTypeTriple) != 0) {
if (builder.length() != startLength)
builder.append(',');
builder.append('#');
}
if ((bondTypes & Molecule.cBondTypeQuadruple) != 0) {
if ((bondQFTypes & Molecule.cBondTypeQuadruple) != 0) {
if (builder.length() != startLength)
builder.append(',');
builder.append('$');
}
if ((bondTypes & Molecule.cBondTypeQuintuple) != 0) { // SMILES doesn't support quintuple bonds, thus we use quadruple
if ((bondQFTypes & Molecule.cBondTypeQuintuple) != 0) { // SMILES doesn't support quintuple bonds, thus we use quadruple
if (builder.length() != startLength)
builder.append(',');
builder.append('$');
}
if ((bondTypes & Molecule.cBondTypeDelocalized) != 0) {
if ((bondQFTypes & Molecule.cBondTypeDelocalized) != 0) {
if (builder.length() != startLength)
builder.append(',');
builder.append(':');
}
if ((bondTypes & Molecule.cBondTypeMetalLigand) != 0) {
if ((bondQFTypes & Molecule.cBondTypeMetalLigand) != 0) {
if (builder.length() != startLength)
builder.append(',');
builder.append(mMol.isMetalAtom(parentAtom) ? "<-" : "->");
Expand Down
33 changes: 13 additions & 20 deletions src/main/java/com/actelion/research/chem/Molecule.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ public class Molecule implements Serializable {
public static final long cAtomQFIsNotStereo = 0x0000200000000000L;
public static final long cAtomQFHeteroAromatic = 0x0000400000000000L;

public static final int cBondTypeSingle = 0x00000001;
public static final int cBondTypeDouble = 0x00000002;
public static final int cBondTypeTriple = 0x00000004;
public static final int cBondTypeQuadruple = 0x00000008;
public static final int cBondTypeQuintuple = 0x00000010;
public static final int cBondTypeMetalLigand = 0x00000020;
public static final int cBondTypeDelocalized = 0x00000040;
public static final int cBondTypeSingle = 0x00000001; // first 5 bond types must not be changed,
public static final int cBondTypeDouble = 0x00000002; // because they are part of the idcode
public static final int cBondTypeTriple = 0x00000004; // within the bond query features
public static final int cBondTypeDelocalized = 0x00000008;
public static final int cBondTypeMetalLigand = 0x00000010;
public static final int cBondTypeQuadruple = 0x00000020;
public static final int cBondTypeQuintuple = 0x00000040;
public static final int cBondTypeDown = 0x00000081;
public static final int cBondTypeUp = 0x00000101;
public static final int cBondTypeCross = 0x00000182;
Expand Down Expand Up @@ -279,13 +279,6 @@ public class Molecule implements Serializable {
public static final int cBondQFNarrowing = 0x00600180;
public static final int cBondQFBondTypes = 0x0000001F; // original 5 bond types for idcode
public static final int cBondQFRareBondTypes = 0x00000060; // using OR logic for all 7 bond types
public static final int cBondQFSingle = 0x00000001;
public static final int cBondQFDouble = 0x00000002;
public static final int cBondQFTriple = 0x00000004;
public static final int cBondQFDelocalized = 0x00000008;
public static final int cBondQFMetalLigand = 0x00000010;
public static final int cBondQFQuadruple = 0x00000020;
public static final int cBondQFQuintuple = 0x00000040;
public static final int cBondQFRingState = 0x00000180;
public static final int cBondQFNotRing = 0x00000080;
public static final int cBondQFRing = 0x00000100;
Expand Down Expand Up @@ -2664,17 +2657,17 @@ public double getBondLength(int bond) {
*/
public int getBondOrder(int bond) {
if (mIsFragment && (mBondQueryFeatures[bond] & cBondQFBondTypes) != 0) {
if ((mBondQueryFeatures[bond] & (cBondQFSingle | cBondQFDelocalized)) != 0)
if ((mBondQueryFeatures[bond] & (cBondTypeSingle | cBondTypeDelocalized)) != 0)
return 1;
if ((mBondQueryFeatures[bond] & cBondQFDouble) != 0)
if ((mBondQueryFeatures[bond] & cBondTypeDouble) != 0)
return 2;
if ((mBondQueryFeatures[bond] & cBondQFTriple) != 0)
if ((mBondQueryFeatures[bond] & cBondTypeTriple) != 0)
return 3;
if ((mBondQueryFeatures[bond] & cBondQFQuadruple) != 0)
if ((mBondQueryFeatures[bond] & cBondTypeQuadruple) != 0)
return 4;
if ((mBondQueryFeatures[bond] & cBondQFQuintuple) != 0)
if ((mBondQueryFeatures[bond] & cBondTypeQuintuple) != 0)
return 5;
if ((mBondQueryFeatures[bond] & cBondQFMetalLigand) != 0)
if ((mBondQueryFeatures[bond] & cBondTypeMetalLigand) != 0)
return 0;
}
switch (mBondType[bond] & cBondTypeMaskSimple) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/actelion/research/chem/MolfileCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ else if (mol.getAtomESRType(atom) == Molecule.cESRTypeAnd
// if query features cannot be expressed exactly stay on the loosely defined side
int bondType = mol.getBondQueryFeatures(bond) & Molecule.cBondQFBondTypes;
if (bondType != 0) {
if (bondType == Molecule.cBondQFDelocalized)
if (bondType == Molecule.cBondTypeDelocalized)
order = 4; // aromatic
else if (bondType == (Molecule.cBondQFSingle | Molecule.cBondQFDouble))
else if (bondType == (Molecule.cBondTypeSingle | Molecule.cBondTypeDouble))
order = 5; // single or double
else if (bondType == (Molecule.cBondQFSingle | Molecule.cBondQFDelocalized))
else if (bondType == (Molecule.cBondTypeSingle | Molecule.cBondTypeDelocalized))
order = 6; // single or aromatic
else if (bondType == (Molecule.cBondQFDouble | Molecule.cBondQFDelocalized))
else if (bondType == (Molecule.cBondTypeDouble | Molecule.cBondTypeDelocalized))
order = 7; // single or double
else
order = 8; // any
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/actelion/research/chem/MolfileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,13 @@ private int buildBond(int atom1,int atom2,int bondType,
if(bondType > 4){
switch(bondType){
case 5:
queryFeatures |= Molecule.cBondQFSingle | Molecule.cBondQFDouble;
queryFeatures |= Molecule.cBondTypeSingle | Molecule.cBondTypeDouble;
break;
case 6:
queryFeatures |= Molecule.cBondQFSingle | Molecule.cBondQFDelocalized;
queryFeatures |= Molecule.cBondTypeSingle | Molecule.cBondTypeDelocalized;
break;
case 7:
queryFeatures |= Molecule.cBondQFDouble | Molecule.cBondQFDelocalized;
queryFeatures |= Molecule.cBondTypeDouble | Molecule.cBondTypeDelocalized;
break;
case 8:
if (realBondType != Molecule.cBondTypeMetalLigand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,16 @@ else if (ringFeatures == (Molecule.cAtomQFNotChain | Molecule.cAtomQFNot2RingBon
// if query features cannot be expressed exactly stay on the loosely defined side
int bondType = mol.getBondQueryFeatures(bond) & Molecule.cBondQFBondTypes;
if (bondType != 0) {
if (bondType == Molecule.cBondQFDelocalized) {
if (bondType == Molecule.cBondTypeDelocalized) {
order = 4; // aromatic
}
else if (bondType == (Molecule.cBondQFSingle | Molecule.cBondQFDouble)) {
else if (bondType == (Molecule.cBondTypeSingle | Molecule.cBondTypeDouble)) {
order = 5; // single or double
}
else if (bondType == (Molecule.cBondQFSingle | Molecule.cBondQFDelocalized)) {
else if (bondType == (Molecule.cBondTypeSingle | Molecule.cBondTypeDelocalized)) {
order = 6; // single or aromatic
}
else if (bondType == (Molecule.cBondQFDouble | Molecule.cBondQFDelocalized)) {
else if (bondType == (Molecule.cBondTypeDouble | Molecule.cBondTypeDelocalized)) {
order = 7; // single or double
}
else {
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/com/actelion/research/chem/SSSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -1300,13 +1300,13 @@ public boolean areBondsSimilar(int moleculeBond, int fragmentBond) {
int frgBondType = mFragment.getBondTypeSimple(fragmentBond);
int frgBondTypes = mFragment.getBondQueryFeatures(fragmentBond) & Molecule.cBondQFBondTypes;
if (molBondType != frgBondType
&& !(molBondType == Molecule.cBondTypeSingle && (frgBondTypes & Molecule.cBondQFSingle) != 0)
&& !(molBondType == Molecule.cBondTypeDouble && (frgBondTypes & Molecule.cBondQFDouble) != 0)
&& !(molBondType == Molecule.cBondTypeTriple && (frgBondTypes & Molecule.cBondQFTriple) != 0)
&& !(molBondType == Molecule.cBondTypeQuadruple && (frgBondTypes & Molecule.cBondQFQuadruple) != 0)
&& !(molBondType == Molecule.cBondTypeQuintuple && (frgBondTypes & Molecule.cBondQFQuintuple) != 0)
&& !(molBondType == Molecule.cBondTypeMetalLigand && (frgBondTypes & Molecule.cBondQFMetalLigand) != 0)
&& !(molBondType == Molecule.cBondTypeDelocalized && (frgBondTypes & Molecule.cBondQFDelocalized) != 0))
&& !(molBondType == Molecule.cBondTypeSingle && (frgBondTypes & Molecule.cBondTypeSingle) != 0)
&& !(molBondType == Molecule.cBondTypeDouble && (frgBondTypes & Molecule.cBondTypeDouble) != 0)
&& !(molBondType == Molecule.cBondTypeTriple && (frgBondTypes & Molecule.cBondTypeTriple) != 0)
&& !(molBondType == Molecule.cBondTypeQuadruple && (frgBondTypes & Molecule.cBondTypeQuadruple) != 0)
&& !(molBondType == Molecule.cBondTypeQuintuple && (frgBondTypes & Molecule.cBondTypeQuintuple) != 0)
&& !(molBondType == Molecule.cBondTypeMetalLigand && (frgBondTypes & Molecule.cBondTypeMetalLigand) != 0)
&& !(molBondType == Molecule.cBondTypeDelocalized && (frgBondTypes & Molecule.cBondTypeDelocalized) != 0))
return false;

molDefaults &= ~Molecule.cBondQFBondTypes;
Expand Down Expand Up @@ -1588,13 +1588,13 @@ else if (ringSize == 7)

// match fragment's single/double bonds to delocalized molecule bonds also
if ((matchMode & cMatchDBondToDelocalized) != 0) {
if ((mFragmentBondFeatures[bond] & Molecule.cBondQFDouble) != 0)
mFragmentBondFeatures[bond] |= Molecule.cBondQFDelocalized;
if ((mFragmentBondFeatures[bond] & Molecule.cBondTypeDouble) != 0)
mFragmentBondFeatures[bond] |= Molecule.cBondTypeDelocalized;
}
else if ((matchMode & cMatchAromDBondToDelocalized) != 0) {
if ((mFragmentBondFeatures[bond] & Molecule.cBondQFDouble) != 0
if ((mFragmentBondFeatures[bond] & Molecule.cBondTypeDouble) != 0
&& fragment.isAromaticBond(bond))
mFragmentBondFeatures[bond] |= Molecule.cBondQFDelocalized;
mFragmentBondFeatures[bond] |= Molecule.cBondTypeDelocalized;
}
}
}
Expand Down Expand Up @@ -1801,25 +1801,25 @@ private int getBondQueryDefaults(StereoMolecule mol, int bond) {

if (mol.isDelocalizedBond(bond)
|| mol.getBondType(bond) == Molecule.cBondTypeDelocalized)
queryDefaults |= Molecule.cBondQFDelocalized;
queryDefaults |= Molecule.cBondTypeDelocalized;
else switch (mol.getBondOrder(bond)) {
case 0:
queryDefaults |= Molecule.cBondTypeMetalLigand;
break;
case 1:
queryDefaults |= Molecule.cBondQFSingle;
queryDefaults |= Molecule.cBondTypeSingle;
break;
case 2:
queryDefaults |= Molecule.cBondQFDouble;
queryDefaults |= Molecule.cBondTypeDouble;
break;
case 3:
queryDefaults |= Molecule.cBondQFTriple;
queryDefaults |= Molecule.cBondTypeTriple;
break;
case 4:
queryDefaults |= Molecule.cBondQFQuadruple;
queryDefaults |= Molecule.cBondTypeQuadruple;
break;
case 5:
queryDefaults |= Molecule.cBondQFQuintuple;
queryDefaults |= Molecule.cBondTypeQuintuple;
break;
}

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/actelion/research/chem/SmilesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,15 @@ else if ((theChar == '-' && smiles[position] == '>')
position++;
}
else if (theChar == '-')
excludedBonds |= Molecule.cBondQFSingle;
excludedBonds |= Molecule.cBondTypeSingle;
else if (theChar == '=')
excludedBonds |= Molecule.cBondQFDouble;
excludedBonds |= Molecule.cBondTypeDouble;
else if (theChar == '#')
excludedBonds |= Molecule.cBondQFTriple;
excludedBonds |= Molecule.cBondTypeTriple;
else if (theChar == '$')
excludedBonds |= Molecule.cBondQFQuadruple;
excludedBonds |= Molecule.cBondTypeQuadruple;
else if (theChar == ':')
excludedBonds |= Molecule.cBondQFDelocalized;
excludedBonds |= Molecule.cBondTypeDelocalized;
else
throw new Exception("SmilesParser: bond symbol '"+theChar+"' not allowed after '!'. Position:"+(position-1));
}
Expand All @@ -514,7 +514,7 @@ else if (theChar == '$')
else if (theChar == ':')
bondType = Molecule.cBondTypeDelocalized;
else if (theChar == '~')
bondQueryFeatures |= Molecule.cBondQFSingle | Molecule.cBondQFDouble | Molecule.cBondQFTriple | Molecule.cBondQFDelocalized;
bondQueryFeatures |= Molecule.cBondTypeSingle | Molecule.cBondTypeDouble | Molecule.cBondTypeTriple | Molecule.cBondTypeDelocalized;
else if (theChar == '/') {
if (readStereoFeatures)
bondType = Molecule.cBondTypeUp; // encode slash temporarily in bondType
Expand Down Expand Up @@ -860,12 +860,12 @@ private boolean isBondSymbol(char theChar) {
}

private int bondSymbolToQueryFeature(char symbol) {
return symbol == '=' ? Molecule.cBondQFDouble
: symbol == '#' ? Molecule.cBondQFTriple
: symbol == '$' ? Molecule.cBondQFQuadruple
: symbol == ':' ? Molecule.cBondQFDelocalized
: symbol == '>' ? Molecule.cBondQFMetalLigand
: symbol == '~' ? Molecule.cBondQFBondTypes : Molecule.cBondQFSingle;
return symbol == '=' ? Molecule.cBondTypeDouble
: symbol == '#' ? Molecule.cBondTypeTriple
: symbol == '$' ? Molecule.cBondTypeQuadruple
: symbol == ':' ? Molecule.cBondTypeDelocalized
: symbol == '>' ? Molecule.cBondTypeMetalLigand
: symbol == '~' ? Molecule.cBondQFBondTypes : Molecule.cBondTypeSingle;
}

protected void smartsWarning(String feature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public StereoMolecule createGenericTautomer() {
for (int bond=0; bond<mol.getBonds(); bond++) {
if (mIsTautomerBond[bond]) {
mol.setBondType(bond, Molecule.cBondTypeSingle);
mol.setBondQueryFeature(bond, Molecule.cBondQFSingle | Molecule.cBondQFDouble, true);
mol.setBondQueryFeature(bond, Molecule.cBondTypeSingle | Molecule.cBondTypeDouble, true);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/actelion/research/chem/reaction/Reactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -682,17 +682,17 @@ else if (productParityHint == Molecule.cAtomQFRxnParityRacemize) {
int rBondOrder = mReactant[i].getBondOrder(rBond);

// only consider simple bond order features
reactantQFBondType &= Molecule.cBondQFSingle | Molecule.cBondQFDouble | Molecule.cBondQFTriple;
productQFBondType &= Molecule.cBondQFSingle | Molecule.cBondQFDouble | Molecule.cBondQFTriple;
reactantQFBondType &= Molecule.cBondTypeSingle | Molecule.cBondTypeDouble | Molecule.cBondTypeTriple;
productQFBondType &= Molecule.cBondTypeSingle | Molecule.cBondTypeDouble | Molecule.cBondTypeTriple;

// increase in bond order
if (reactantQFBondType == (Molecule.cBondQFSingle | Molecule.cBondQFDouble)
&& productQFBondType == (Molecule.cBondQFDouble | Molecule.cBondQFTriple)) {
if (reactantQFBondType == (Molecule.cBondTypeSingle | Molecule.cBondTypeDouble)
&& productQFBondType == (Molecule.cBondTypeDouble | Molecule.cBondTypeTriple)) {
product.setBondType(productBond, rBondOrder <= 1 ? Molecule.cBondTypeDouble : Molecule.cBondTypeTriple);
}
// decrease in bond order
else if (reactantQFBondType == (Molecule.cBondQFDouble | Molecule.cBondQFTriple)
&& productQFBondType == (Molecule.cBondQFSingle | Molecule.cBondQFDouble)) {
else if (reactantQFBondType == (Molecule.cBondTypeDouble | Molecule.cBondTypeTriple)
&& productQFBondType == (Molecule.cBondTypeSingle | Molecule.cBondTypeDouble)) {
product.setBondType(productBond, rBondOrder == 3 ? Molecule.cBondTypeDouble : Molecule.cBondTypeSingle);
}
else {
Expand Down
Loading

0 comments on commit 3f2b0b2

Please sign in to comment.