public void TestGetBondLengthValue_String_String() { var parser = CDK.SmilesParser; var smiles = "CCCCCC"; var molecule = parser.ParseSmiles(smiles); Assert.IsNotNull(molecule); ForceFieldConfigurator ffc = new ForceFieldConfigurator(); ffc.SetForceFieldConfigurator("mmff94"); AtomPlacer3D atomPlacer3d = new AtomPlacer3D(ffc.GetParameterSet()); ffc.AssignAtomTyps(molecule); string id1 = molecule.Atoms[1].AtomTypeName; string id2 = molecule.Atoms[2].AtomTypeName; string mmff94id1 = "C"; string mmff94id2 = "C"; Assert.AreNotSame(mmff94id1, id1); Assert.AreNotSame(mmff94id2, id2); double bondlength = atomPlacer3d.GetBondLengthValue(id1, id2); Assert.AreEqual(1.508, bondlength, 0.001); }
[TestMethod(), Ignore()] // Old atom typing method - see new Mmff class public void TestAssignAtomTyps_test4_hydroxyurea() { var smiles = "C(=O)(NO)N"; string[] originalAtomTypes = { "C.sp2", "O.sp2", "N.amide", "O.sp3", "N.amide" }; string[] expectedAtomTypes = { "C=", "O=", "NC=O", "O", "N2OX" }; IAtomContainer molecule = null; string[] ffAtomTypes = null; var smilesParser = CDK.SmilesParser; molecule = smilesParser.ParseSmiles(smiles); ffAtomTypes = new string[molecule.Atoms.Count]; for (int i = 0; i < molecule.Atoms.Count; i++) { Assert.AreEqual(originalAtomTypes[i], molecule.Atoms[i].AtomTypeName); } forceFieldConfigurator.SetForceFieldConfigurator("mmff94"); IRingSet moleculeRingSet = forceFieldConfigurator.AssignAtomTyps(molecule); //no rings Assert.AreEqual(0, moleculeRingSet.Count); for (int i = 0; i < molecule.Atoms.Count; i++) { IAtom mmff94atom = molecule.Atoms[i]; Assert.IsTrue(mmff94atom.IsAliphatic); ffAtomTypes[i] = mmff94atom.AtomTypeName; } Assert.AreEqual(expectedAtomTypes, ffAtomTypes); }
public void InvalidChain() { string input = "CCCCCC(CCCC)CCCC"; var sp = CDK.SmilesParser; var m = sp.ParseSmiles(input); ForceFieldConfigurator ffc = new ForceFieldConfigurator(); ffc.SetForceFieldConfigurator("mmff92"); ffc.AssignAtomTyps(m); AtomPlacer3D ap3d = new AtomPlacer3D(ffc.GetParameterSet()); ap3d.PlaceAliphaticHeavyChain(m, m); }
public void TestMapTemplates_IAtomContainer_Double() { var ac = TestMoleculeFactory.MakeBicycloRings(); var th3d = TemplateHandler3D.Instance; var ffc = new ForceFieldConfigurator(); ffc.SetForceFieldConfigurator("mm2"); var ringSetMolecule = ffc.AssignAtomTyps(ac); var ringSystems = RingPartitioner.PartitionRings(ringSetMolecule); var largestRingSet = RingSetManipulator.GetLargestRingSet(ringSystems); var largestRingSetContainer = RingSetManipulator.GetAllInOneContainer(largestRingSet); th3d.MapTemplates(largestRingSetContainer, largestRingSetContainer.Atoms.Count); for (int i = 0; i < ac.Atoms.Count; i++) { Assert.IsNotNull(ac.Atoms[i].Point3D); } ModelBuilder3DTest.CheckAverageBondLength(ac); }
public void TestMapTemplatesCyclicMol2() { TemplateHandler3D tmphandler3d = TemplateHandler3D.Instance; string cyclicMolSmi = "CC(C)(C)NC(=O)C1CN(CCN1CC(CC(Cc1ccccc1)C(=O)NC1c2ccccc2CC1O)O)Cc1cccnc1"; IChemObjectBuilder builder = ChemObjectBuilder.Instance; SmilesParser smiparser = new SmilesParser(builder); var molecule = smiparser.ParseSmiles(cyclicMolSmi); ForceFieldConfigurator forcefconf = new ForceFieldConfigurator(); forcefconf.SetForceFieldConfigurator("mmff94"); IRingSet rings = forcefconf.AssignAtomTyps(molecule); var ringSystems = RingPartitioner.PartitionRings(rings); IRingSet largestRingSet = RingSetManipulator.GetLargestRingSet(ringSystems); IAtomContainer allAtomsInOneContainer = RingSetManipulator.GetAllInOneContainer(largestRingSet); tmphandler3d.MapTemplates(allAtomsInOneContainer, allAtomsInOneContainer.Atoms.Count); for (int j = 0; j < allAtomsInOneContainer.Atoms.Count; j++) { Assert.IsNotNull(allAtomsInOneContainer.Atoms[j].Point3D); } }
public void TestGetAngleValue_String_String_String() { var parser = CDK.SmilesParser; var smiles = "CCCCCC"; var molecule = parser.ParseSmiles(smiles); Assert.IsNotNull(molecule); ForceFieldConfigurator ffc = new ForceFieldConfigurator(); ffc.SetForceFieldConfigurator("mmff94"); AtomPlacer3D atomPlacer3d = new AtomPlacer3D(ffc.GetParameterSet()); ffc.AssignAtomTyps(molecule); string id1 = molecule.Atoms[1].AtomTypeName; string id2 = molecule.Atoms[2].AtomTypeName; string id3 = molecule.Atoms[3].AtomTypeName; double anglev = atomPlacer3d.GetAngleValue(id1, id2, id3); Assert.AreEqual(109.608, anglev, 0.001); }
/// <summary> /// Generate 3D coordinates with force field information. /// </summary> public IAtomContainer Generate3DCoordinates(IAtomContainer molecule, bool clone) { var originalAtomTypeNames = molecule.Atoms.Select(n => n.AtomTypeName).ToArray(); Debug.WriteLine("******** GENERATE COORDINATES ********"); foreach (var atom in molecule.Atoms) { atom.IsPlaced = false; atom.IsVisited = false; } //CHECK FOR CONNECTIVITY! Debug.WriteLine($"#atoms>{molecule.Atoms.Count}"); if (!ConnectivityChecker.IsConnected(molecule)) { throw new CDKException("Molecule is NOT connected, could not layout."); } // setup helper classes AtomPlacer atomPlacer = new AtomPlacer(); AtomPlacer3D ap3d = new AtomPlacer3D(parameterSet); AtomTetrahedralLigandPlacer3D atlp3d = new AtomTetrahedralLigandPlacer3D(parameterSet); if (clone) { molecule = (IAtomContainer)molecule.Clone(); } atomPlacer.Molecule = molecule; if (ap3d.NumberOfUnplacedHeavyAtoms(molecule) == 1) { Debug.WriteLine("Only one Heavy Atom"); ap3d.GetUnplacedHeavyAtom(molecule).Point3D = new Vector3(0.0, 0.0, 0.0); try { atlp3d.Add3DCoordinatesForSinglyBondedLigands(molecule); } catch (CDKException ex3) { Trace.TraceError($"PlaceSubstitutensERROR: Cannot place substitutents due to:{ex3.Message}"); Debug.WriteLine(ex3); throw new CDKException("PlaceSubstitutensERROR: Cannot place substitutents due to:" + ex3.Message, ex3); } return(molecule); } //Assing Atoms to Rings,Aliphatic and Atomtype IRingSet ringSetMolecule = ffc.AssignAtomTyps(molecule); IRingSet largestRingSet = null; int numberOfRingAtoms = 0; IReadOnlyList <IRingSet> ringSystems = null; if (ringSetMolecule.Count > 0) { if (templateHandler == null) { throw new CDKException("You are trying to generate coordinates for a molecule with rings, but you have no template handler set. Please do SetTemplateHandler() before generation!"); } ringSystems = RingPartitioner.PartitionRings(ringSetMolecule); largestRingSet = RingSetManipulator.GetLargestRingSet(ringSystems); IAtomContainer largestRingSetContainer = RingSetManipulator.GetAllInOneContainer(largestRingSet); numberOfRingAtoms = largestRingSetContainer.Atoms.Count; templateHandler.MapTemplates(largestRingSetContainer, numberOfRingAtoms); if (!CheckAllRingAtomsHasCoordinates(largestRingSetContainer)) { throw new CDKException("RingAtomLayoutError: Not every ring atom is placed! Molecule cannot be layout."); } SetAtomsToPlace(largestRingSetContainer); SearchAndPlaceBranches(molecule, largestRingSetContainer, ap3d, atlp3d, atomPlacer); largestRingSet = null; } else { //Debug.WriteLine("****** Start of handling aliphatic molecule ******"); IAtomContainer ac = AtomPlacer.GetInitialLongestChain(molecule); SetAtomsToUnVisited(molecule); SetAtomsToUnplaced(molecule); ap3d.PlaceAliphaticHeavyChain(molecule, ac); //ZMatrixApproach ap3d.ZMatrixChainToCartesian(molecule, false); SearchAndPlaceBranches(molecule, ac, ap3d, atlp3d, atomPlacer); } LayoutMolecule(ringSystems, molecule, ap3d, atlp3d, atomPlacer); //Debug.WriteLine("******* PLACE SUBSTITUENTS ******"); try { atlp3d.Add3DCoordinatesForSinglyBondedLigands(molecule); } catch (CDKException ex3) { Trace.TraceError($"PlaceSubstitutensERROR: Cannot place substitutents due to:{ex3.Message}"); Debug.WriteLine(ex3); throw new CDKException("PlaceSubstitutensERROR: Cannot place substitutents due to:" + ex3.Message, ex3); } // restore the original atom type names for (int i = 0; i < originalAtomTypeNames.Length; i++) { molecule.Atoms[i].AtomTypeName = originalAtomTypeNames[i]; } return(molecule); }