public void TestGetNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour_IAtomContainer()
        {
            AtomPlacer3D   atmplacer     = new AtomPlacer3D();
            IAtomContainer benzene       = TestMoleculeFactory.MakeBenzene();
            IAtomContainer acyclicAlkane = TestMoleculeFactory.MakeAlkane(5);

            foreach (var atom in benzene.Atoms)
            {
                atom.IsInRing = true;
            }
            foreach (var atom in acyclicAlkane.Atoms)
            {
                atom.IsAliphatic = true;
            }

            for (int j = 0; j < 3; j++)
            {
                benzene.Atoms[j].IsPlaced = true;
            }
            IAtom searchedatom1 = atmplacer.GetNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(benzene);

            Assert.IsNull(searchedatom1);

            foreach (var atom in benzene.Atoms)
            {
                if (!atom.IsPlaced)
                {
                    atom.IsPlaced = true;
                }
            }
            IAtom searchedatom2 = atmplacer.GetNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(benzene);

            Assert.IsNull(searchedatom2);

            for (int k = 0; k < 3; k++)
            {
                acyclicAlkane.Atoms[k].IsPlaced = true;
            }
            IAtom nextAtom = atmplacer.GetNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(acyclicAlkane);

            Assert.AreEqual(acyclicAlkane.Atoms[2], nextAtom);
        }
Beispiel #2
0
        /// <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);
        }