Skip to content

Commit c6be0ae

Browse files
Tosco, Paologreglandrum
authored andcommitted
only clear wedge bond flags after normalization
1 parent ab1b03a commit c6be0ae

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/types/RDKitMolValueRenderer.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.RDKit.RDKFuncs;
6868
import org.RDKit.ROMol;
6969
import org.RDKit.RWMol;
70+
import org.RDKit.Bond;
7071
import org.apache.batik.anim.dom.SAXSVGDocumentFactory;
7172
import org.apache.batik.util.XMLResourceDescriptor;
7273
import org.knime.base.data.xml.SvgProvider;
@@ -568,6 +569,37 @@ public static int compute2DCoords(ROMol mol, boolean bUseCoordGen, boolean bNorm
568569
return compute2DCoords(mol, (Int_Point2D_Map)null, bUseCoordGen, bNormalize);
569570
}
570571

572+
/**
573+
* Clears the single bond direction flags of the passed in molecule.
574+
* If bOnlyWedgeFlags is true, only the wedge flags are cleared, otherwise
575+
* all single bond direction flags are cleared.
576+
* FIXME: This method can be replaced with the native clearSingleBondDirFlags
577+
* method once the RDKit version is updated to 2025_03_4 or later
578+
* @param mol Molecule to clear the single bond direction flags for. Can be null to do nothing.
579+
* @param bOnlyWedgeFlags If true, only the wedge flags are cleared, otherwise
580+
* all single bond direction flags are cleared.
581+
*/
582+
public static void clearSingleBondDirFlags(ROMol mol, boolean bOnlyWedgeFlags) {
583+
if (mol == null) {
584+
return;
585+
}
586+
for (int i = 0; i < mol.getNumBonds(); ++i) {
587+
final Bond bond = mol.getBondWithIdx(i);
588+
if (bond.getBondType() == Bond.BondType.SINGLE) {
589+
if (bond.getBondDir() == Bond.BondDir.UNKNOWN) {
590+
bond.setProp("_UnknownStereo", "1");
591+
}
592+
593+
if (!bOnlyWedgeFlags ||
594+
(bond.getBondDir() != Bond.BondDir.ENDDOWNRIGHT &&
595+
bond.getBondDir() != Bond.BondDir.ENDUPRIGHT)) {
596+
bond.setBondDir(Bond.BondDir.NONE);
597+
}
598+
}
599+
}
600+
}
601+
602+
571603
/**
572604
* Calls the compute2DCoords method on the passed in ROMol object (if not null)
573605
* and passes default parameters except for the last boolean parameter, which
@@ -608,7 +640,7 @@ public static int compute2DCoords(ROMol mol, Int_Point2D_Map mapTemplate, boolea
608640
// canonicalization may flip the molecule around the Z axis,
609641
// so we recompute bond wedging to make sure the stereochemistry
610642
// is depicted correctly (KNIME-1692)
611-
mol.ClearSingleBondDirFlags();
643+
clearSingleBondDirFlags(mol, true);
612644
mol.WedgeMolBonds(mol.getConformer());
613645
}
614646
}

0 commit comments

Comments
 (0)