Exemplo n.º 1
0
        public void TestGetNextPlacedHeavyAtomWithUnplacedRingNeighbour_IAtomContainer()
        {
            AtomPlacer3D   atmplacer     = new AtomPlacer3D();
            IAtomContainer acyclicAlkane = TestMoleculeFactory.MakeAlkane(3);
            IAtomContainer cycloPentane  = TestMoleculeFactory.MakeCyclopentane();

            //TestMoleculeFactory does not set ISINRING flags for cyclic molecules
            Assert.AreEqual(false, cycloPentane.Atoms[0].IsInRing);
            foreach (var atom in cycloPentane.Atoms)
            {
                atom.IsInRing = true;
            }

            //acyclic molecule so null is expected
            foreach (var atom in acyclicAlkane.Atoms)
            {
                atom.IsPlaced = true;
            }
            Assert.IsNull(atmplacer.GetNextPlacedHeavyAtomWithUnplacedRingNeighbour(acyclicAlkane));

            for (int j = 0; j < 3; j++)
            {
                cycloPentane.Atoms[j].IsPlaced = true;
            }
            Assert.AreEqual(cycloPentane.Atoms[2],
                            atmplacer.GetNextPlacedHeavyAtomWithUnplacedRingNeighbour(cycloPentane));
        }
Exemplo n.º 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);
        }