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); } }
/// <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); }