public void TestBug795480() { IAtomContainer molecule = null; HOSECodeGenerator hcg = null; string[] result = { "C-4-;C(=C/Y'+4'/)", "C-3;=CC-(Y'+4',//)", "C-3;=CY'+4'(C-,//)", "Br-1'+4';C(=C/C-/)" }; molecule = CDK.SmilesParser.ParseSmiles("CC=CBr"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); bool isAromatic = Aromaticity.CDKLegacy.Apply(molecule); Assert.IsFalse(isAromatic); molecule.Atoms[0].FormalCharge = -1; molecule.Atoms[3].FormalCharge = +4; hcg = new HOSECodeGenerator(); string s = null; for (int f = 0; f < molecule.Atoms.Count; f++) { s = hcg.GetHOSECode(molecule, molecule.Atoms[f], 4); if (standAlone) { Console.Out.Write("|" + s + "| -> " + result[f]); } Assert.AreEqual(result[f], s); if (standAlone) { Console.Out.WriteLine(" OK"); } } }
public void TestBug655169() { IAtomContainer molecule = null; HOSECodeGenerator hcg = null; string[] result = { "C-4;C(=C/Y/)", "C-3;=CC(Y,//)", "C-3;=CY(C,//)", "Br-1;C(=C/C/)" }; molecule = CDK.SmilesParser.ParseSmiles("CC=CBr"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); Aromaticity.CDKLegacy.Apply(molecule); hcg = new HOSECodeGenerator(); string s = null; for (int f = 0; f < molecule.Atoms.Count; f++) { s = hcg.GetHOSECode(molecule, molecule.Atoms[f], 4); if (standAlone) { Console.Out.Write("|" + s + "| -> " + result[f]); } Assert.AreEqual(result[f], s); if (standAlone) { Console.Out.WriteLine(" OK"); } } }
public void Test4() { string[] result = { "C-3;*C*C*C(*C*N,*C,*C/*C,*&,*&,*&/*&)", "C-3;*C*C(*C*C,*N/*C*&,*C,*&/*C,*&)", "C-3;*C*N(*C,*C/*&*C,*&*C/,*C,*C)", "N-3;*C*C(*C*C,*C/*C*&,*C,*&/*C,*&)", "C-3;*C*C*N(*C*C,*C,*C/*C,*&,*&,*&/*&)", "C-3;*C*C(*C*N,*C/*C*C,*C,*&/*&,*&,*&)", "C-3;*C*C(*C,*C/*C*N,*&/*&*C,*C)", "C-3;*C*C(*C,*C/*C*C,*&/*&*N,*C)", "C-3;*C*C(*C*C,*C/*C*N,*C,*&/*&,*&,*&)" }; IAtomContainer molecule = CDK.SmilesParser .ParseSmiles("C1(C=CN2)=C2C=CC=C1"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); Aromaticity.CDKLegacy.Apply(molecule); //Display(molecule); HOSECodeGenerator hcg = new HOSECodeGenerator(); string s = null; for (int f = 0; f < molecule.Atoms.Count; f++) { s = hcg.GetHOSECode(molecule, molecule.Atoms[f], 4); if (standAlone) { Console.Out.WriteLine(f + "|" + s + "| -> " + result[f]); } Assert.AreEqual(result[f], s); if (standAlone) { Console.Out.WriteLine(" OK"); } } }
/// <summary> /// Method assigns certain properties to an atom. Necessary for the atom type matching /// Properties: /// <list type="bullet"> /// <item>aromaticity</item> /// <item>ChemicalGroup (CDKChemicalRingGroupConstant)</item> /// <item> /// <item>SSSR</item> /// <item>Ring/Group, ringSize, aromaticity</item> /// <item>SphericalMatcher (HoSe Code)</item> /// </item> /// </list> /// </summary> /// <param name="molecule"></param> /// <param name="aromaticity"><see langword="true"/> if aromaticity should be calculated</param> /// <returns>sssrf ring set of the molecule</returns> public static IRingSet AssignAtomTypePropertiesToAtom(IAtomContainer molecule, bool aromaticity) { var sg = new SmilesGenerator(); Debug.WriteLine("assignAtomTypePropertiesToAtom Start ..."); string hoseCode = ""; var ringSetMolecule = Cycles.FindSSSR(molecule).ToRingSet(); Debug.WriteLine(ringSetMolecule); if (aromaticity) { try { Aromaticity.CDKLegacy.Apply(molecule); } catch (Exception cdk1) { Trace.TraceError($"AROMATICITYError: Cannot determine aromaticity due to: {cdk1.ToString()}"); } } for (int i = 0; i < molecule.Atoms.Count; i++) { // FIXME: remove casting var atom2 = molecule.Atoms[i]; //Atom aromatic is set by HueckelAromaticityDetector //Atom in ring? if (ringSetMolecule.Contains(atom2)) { var ringSetA = ringSetMolecule.Builder.NewRingSet(); ringSetA.AddRange(ringSetMolecule.GetRings(atom2)); RingSetManipulator.Sort(ringSetA); var sring = ringSetA.Last(); atom2.SetProperty(CDKPropertyName.PartOfRingOfSize, sring.RingSize); atom2.SetProperty( CDKPropertyName.ChemicalGroupConstant, RingSystemClassifier(sring, GetSubgraphSmiles(sring, molecule))); atom2.IsInRing = true; atom2.IsAliphatic = false; } else { atom2.SetProperty(CDKPropertyName.ChemicalGroupConstant, NotInRing); atom2.IsInRing = false; atom2.IsAliphatic = true; } try { hoseCode = hcg.GetHOSECode(molecule, atom2, 3); hoseCode = RemoveAromaticityFlagsFromHoseCode(hoseCode); atom2.SetProperty(CDKPropertyName.SphericalMatcher, hoseCode); } catch (CDKException ex1) { throw new CDKException($"Could not build HOSECode from atom {i} due to {ex1.ToString()}", ex1); } } return(ringSetMolecule); }
public void TestGetConfidenceLimit() { var result = new double[] { 28.5, 25.7, 28.5, 34.9, 28.5, 25.7, 25.4, 28.5, 28.5, 14.8, 13.3, 23.0, 34.9, 25.7, 25.7, 28.5, 25.7, 25.7, 13.3, 14.4, 14.4, 8.9, 14.8, 14.8, 13.3, 13.3, 13.3, 14.4, 14.4, 13.3, 14.4, 14.4, 8.9, 14.8, 14.8, 13.3, 13.3, 13.3, 14.4, 14.4, 13.3, }; IAtomContainer molecule = null; var filename = "NCDK.Data.MDL.BremserPredictionTest.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict); molecule = reader.Read(builder.NewAtomContainer()); double prediction; var bp = new BremserOneSphereHOSECodePredictor(); var hcg = new HOSECodeGenerator(); string s = null; RemoveHydrogens(molecule); for (int f = 0; f < molecule.Atoms.Count; f++) { s = hcg.GetHOSECode(molecule, molecule.Atoms[f], 1); prediction = bp.GetConfidenceLimit(HOSECodeGenerator.MakeBremserCompliant(s)); Assert.AreEqual(result[f], prediction, 0.001); } }
public void Test1Sphere() { string[] result = { "O-1;=C(//)", "C-3;=OCC(//)", "C-3;=CC(//)", "C-3;=CC(//)", "C-3;*C*CC(//)", "C-3;*C*C(//)", "C-3;*C*C(//)", "C-3;*C*CC(//)", "C-3;*C*CC(//)", "C-3;*C*C(//)", "C-3;*C*C(//)", "C-3;*C*C(//)", "C-3;*C*C(//)", "C-3;*C*CO(//)", "O-2;CC(//)", "C-3;*C*CO(//)", "C-3;*C*CO(//)", "O-2;CC(//)", "C-4;O(//)", "C-3;*C*C(//)", "C-3;*C*CC(//)", "C-3;*C*C*C(//)", "C-3;*C*C*C(//)" }; var mol = builder.NewAtomContainer(); IAtom a1 = mol.Builder.NewAtom("O"); a1.Point2D = new Vector2(502.88457268119913, 730.4999999999999); mol.Atoms.Add(a1); IAtom a2 = mol.Builder.NewAtom("C"); a2.Point2D = new Vector2(502.8845726811991, 694.4999999999999); mol.Atoms.Add(a2); IAtom a3 = mol.Builder.NewAtom("C"); a3.Point2D = new Vector2(534.0614872174388, 676.4999999999999); mol.Atoms.Add(a3); IAtom a4 = mol.Builder.NewAtom("C"); a4.Point2D = new Vector2(534.0614872174388, 640.4999999999999); mol.Atoms.Add(a4); IAtom a5 = mol.Builder.NewAtom("C"); a5.Point2D = new Vector2(502.8845726811991, 622.4999999999999); mol.Atoms.Add(a5); IAtom a6 = mol.Builder.NewAtom("C"); a6.Point2D = new Vector2(502.8845726811991, 586.4999999999999); mol.Atoms.Add(a6); IAtom a7 = mol.Builder.NewAtom("C"); a7.Point2D = new Vector2(471.7076581449593, 568.4999999999999); mol.Atoms.Add(a7); IAtom a8 = mol.Builder.NewAtom("C"); a8.Point2D = new Vector2(440.5307436087194, 586.5); mol.Atoms.Add(a8); IAtom a9 = mol.Builder.NewAtom("C"); a9.Point2D = new Vector2(409.35382907247964, 568.5); mol.Atoms.Add(a9); IAtom a10 = mol.Builder.NewAtom("C"); a10.Point2D = new Vector2(409.3538290724796, 532.5); mol.Atoms.Add(a10); IAtom a11 = mol.Builder.NewAtom("C"); a11.Point2D = new Vector2(378.1769145362398, 514.5); mol.Atoms.Add(a11); IAtom a12 = mol.Builder.NewAtom("C"); a12.Point2D = new Vector2(347.0, 532.5); mol.Atoms.Add(a12); IAtom a13 = mol.Builder.NewAtom("C"); a13.Point2D = new Vector2(347.0, 568.5); mol.Atoms.Add(a13); IAtom a14 = mol.Builder.NewAtom("C"); a14.Point2D = new Vector2(378.17691453623985, 586.5); mol.Atoms.Add(a14); IAtom a15 = mol.Builder.NewAtom("O"); a15.Point2D = new Vector2(378.17691453623985, 622.5); mol.Atoms.Add(a15); IAtom a16 = mol.Builder.NewAtom("C"); a16.Point2D = new Vector2(409.3538290724797, 640.5); mol.Atoms.Add(a16); IAtom a17 = mol.Builder.NewAtom("C"); a17.Point2D = new Vector2(409.3538290724797, 676.5); mol.Atoms.Add(a17); IAtom a18 = mol.Builder.NewAtom("O"); a18.Point2D = new Vector2(378.17691453623996, 694.5); mol.Atoms.Add(a18); IAtom a19 = mol.Builder.NewAtom("C"); a19.Point2D = new Vector2(378.17691453624, 730.5); mol.Atoms.Add(a19); IAtom a20 = mol.Builder.NewAtom("C"); a20.Point2D = new Vector2(440.5307436087195, 694.4999999999999); mol.Atoms.Add(a20); IAtom a21 = mol.Builder.NewAtom("C"); a21.Point2D = new Vector2(471.7076581449593, 676.4999999999999); mol.Atoms.Add(a21); IAtom a22 = mol.Builder.NewAtom("C"); a22.Point2D = new Vector2(471.7076581449593, 640.4999999999999); mol.Atoms.Add(a22); IAtom a23 = mol.Builder.NewAtom("C"); a23.Point2D = new Vector2(440.53074360871943, 622.4999999999999); mol.Atoms.Add(a23); IBond b1 = mol.Builder.NewBond(a2, a1, BondOrder.Double); mol.Bonds.Add(b1); IBond b2 = mol.Builder.NewBond(a3, a2, BondOrder.Single); mol.Bonds.Add(b2); IBond b3 = mol.Builder.NewBond(a4, a3, BondOrder.Double); mol.Bonds.Add(b3); IBond b4 = mol.Builder.NewBond(a5, a4, BondOrder.Single); mol.Bonds.Add(b4); IBond b5 = mol.Builder.NewBond(a6, a5, BondOrder.Single); mol.Bonds.Add(b5); IBond b6 = mol.Builder.NewBond(a7, a6, BondOrder.Double); mol.Bonds.Add(b6); IBond b7 = mol.Builder.NewBond(a8, a7, BondOrder.Single); mol.Bonds.Add(b7); IBond b8 = mol.Builder.NewBond(a9, a8, BondOrder.Single); mol.Bonds.Add(b8); IBond b9 = mol.Builder.NewBond(a10, a9, BondOrder.Single); mol.Bonds.Add(b9); IBond b10 = mol.Builder.NewBond(a11, a10, BondOrder.Double); mol.Bonds.Add(b10); IBond b11 = mol.Builder.NewBond(a12, a11, BondOrder.Single); mol.Bonds.Add(b11); IBond b12 = mol.Builder.NewBond(a13, a12, BondOrder.Double); mol.Bonds.Add(b12); IBond b13 = mol.Builder.NewBond(a14, a13, BondOrder.Single); mol.Bonds.Add(b13); IBond b14 = mol.Builder.NewBond(a14, a9, BondOrder.Double); mol.Bonds.Add(b14); IBond b15 = mol.Builder.NewBond(a15, a14, BondOrder.Single); mol.Bonds.Add(b15); IBond b16 = mol.Builder.NewBond(a16, a15, BondOrder.Single); mol.Bonds.Add(b16); IBond b17 = mol.Builder.NewBond(a17, a16, BondOrder.Double); mol.Bonds.Add(b17); IBond b18 = mol.Builder.NewBond(a18, a17, BondOrder.Single); mol.Bonds.Add(b18); IBond b19 = mol.Builder.NewBond(a19, a18, BondOrder.Single); mol.Bonds.Add(b19); IBond b20 = mol.Builder.NewBond(a20, a17, BondOrder.Single); mol.Bonds.Add(b20); IBond b21 = mol.Builder.NewBond(a21, a20, BondOrder.Double); mol.Bonds.Add(b21); IBond b22 = mol.Builder.NewBond(a21, a2, BondOrder.Single); mol.Bonds.Add(b22); IBond b23 = mol.Builder.NewBond(a22, a21, BondOrder.Single); mol.Bonds.Add(b23); IBond b24 = mol.Builder.NewBond(a22, a5, BondOrder.Double); mol.Bonds.Add(b24); IBond b25 = mol.Builder.NewBond(a23, a22, BondOrder.Single); mol.Bonds.Add(b25); IBond b26 = mol.Builder.NewBond(a23, a16, BondOrder.Single); mol.Bonds.Add(b26); IBond b27 = mol.Builder.NewBond(a23, a8, BondOrder.Double); mol.Bonds.Add(b27); AddImplicitHydrogens(mol); //MoleculeViewer2D.Display(molecule, true); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol); Aromaticity.CDKLegacy.Apply(mol); HOSECodeGenerator hcg = new HOSECodeGenerator(); string s = null; for (int f = 0; f < 23; f++) { s = hcg.GetHOSECode(mol, mol.Atoms[f], 1); if (standAlone) { Console.Out.Write("|" + s + "| -> " + result[f]); } Assert.AreEqual(result[f], s); if (standAlone) { Console.Out.WriteLine(" OK"); } } }