public void TestGetUnplacedRingHeavyAtom_IAtomContainer_IAtom() { AtomPlacer3D atmplacer = new AtomPlacer3D(); IAtomContainer molecule = TestMoleculeFactory.MakeCyclopentane(); foreach (var atom in molecule.Atoms) { atom.IsInRing = true; } for (int j = 0; j < 2; j++) { molecule.Atoms[j].IsPlaced = true; } IAtom atom0 = molecule.Atoms[0]; IAtom atom1 = molecule.Atoms[1]; IAtom natom = molecule.Atoms[4]; IAtom atom0pair = atmplacer.GetUnplacedRingHeavyAtom(molecule, atom0); IAtom atom1pair = atmplacer.GetUnplacedRingHeavyAtom(molecule, atom1); IAtom natompair = atmplacer.GetUnplacedRingHeavyAtom(molecule, natom); Assert.AreEqual(atom0pair, molecule.Atoms[4]); Assert.AreEqual(atom1pair, molecule.Atoms[2]); Assert.AreEqual(atom0.IsPlaced, true); foreach (var bond in molecule.Bonds) { if (bond.GetOther(molecule.Atoms[4]) != null && !bond.GetOther(molecule.Atoms[4]).IsPlaced) { natompair = bond.GetOther(molecule.Atoms[4]); } } Assert.AreEqual(natompair, molecule.Atoms[3]); }
/// <summary> /// Layout the molecule, starts with ring systems and than aliphatic chains. /// </summary> /// <param name="ringSetMolecule">ringSystems of the molecule</param> private void LayoutMolecule(IReadOnlyList <IRingSet> ringSetMolecule, IAtomContainer molecule, AtomPlacer3D ap3d, AtomTetrahedralLigandPlacer3D atlp3d, AtomPlacer atomPlacer) { //Debug.WriteLine("****** LAYOUT MOLECULE MAIN *******"); IAtomContainer ac = null; int safetyCounter = 0; IAtom atom = null; //Place rest Chains/Atoms do { safetyCounter++; atom = ap3d.GetNextPlacedHeavyAtomWithUnplacedRingNeighbour(molecule); if (atom != null) { //Debug.WriteLine("layout RingSystem..."); var unplacedAtom = ap3d.GetUnplacedRingHeavyAtom(molecule, atom); var ringSetA = GetRingSetOfAtom(ringSetMolecule, unplacedAtom); var ringSetAContainer = RingSetManipulator.GetAllInOneContainer(ringSetA); templateHandler.MapTemplates(ringSetAContainer, ringSetAContainer.Atoms.Count); if (CheckAllRingAtomsHasCoordinates(ringSetAContainer)) { } else { throw new IOException("RingAtomLayoutError: Not every ring atom is placed! Molecule cannot be layout. Sorry"); } Vector3 firstAtomOriginalCoord = unplacedAtom.Point3D.Value; Vector3 centerPlacedMolecule = ap3d.GeometricCenterAllPlacedAtoms(molecule); SetBranchAtom(molecule, unplacedAtom, atom, ap3d.GetPlacedHeavyAtoms(molecule, atom), ap3d, atlp3d); LayoutRingSystem(firstAtomOriginalCoord, unplacedAtom, ringSetA, centerPlacedMolecule, atom, ap3d); SearchAndPlaceBranches(molecule, ringSetAContainer, ap3d, atlp3d, atomPlacer); //Debug.WriteLine("Ready layout Ring System"); ringSetA = null; unplacedAtom = null; } else { //Debug.WriteLine("layout chains..."); SetAtomsToUnVisited(molecule); atom = ap3d.GetNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(molecule); if (atom != null) { ac = atom.Builder.NewAtomContainer(); ac.Atoms.Add(atom); SearchAndPlaceBranches(molecule, ac, ap3d, atlp3d, atomPlacer); ac = null; } } } while (!ap3d.AllHeavyAtomsPlaced(molecule) || safetyCounter > molecule.Atoms.Count); }