Esempio n. 1
0
        /// <summary>
        /// Search and place branches of a chain or ring.
        /// </summary>
        /// <param name="chain">AtomContainer if atoms in an aliphatic chain or ring system</param>
        private void SearchAndPlaceBranches(IAtomContainer molecule, IAtomContainer chain, AtomPlacer3D ap3d,
                                            AtomTetrahedralLigandPlacer3D atlp3d, AtomPlacer atomPlacer)
        {
            //Debug.WriteLine("****** SEARCH AND PLACE ****** Chain length: "+chain.Atoms.Count);
            IAtomContainer branchAtoms    = molecule.Builder.NewAtomContainer();
            IAtomContainer connectedAtoms = molecule.Builder.NewAtomContainer();

            for (int i = 0; i < chain.Atoms.Count; i++)
            {
                var atoms = molecule.GetConnectedAtoms(chain.Atoms[i]);
                foreach (var atom in atoms)
                {
                    if (!atom.AtomicNumber.Equals(AtomicNumbers.H) & !atom.IsPlaced & !atom.IsInRing)
                    {
                        connectedAtoms.Add(ap3d.GetPlacedHeavyAtoms(molecule, chain.Atoms[i]));
                        try
                        {
                            SetBranchAtom(molecule, atom, chain.Atoms[i], connectedAtoms, ap3d, atlp3d);
                        }
                        catch (CDKException ex2)
                        {
                            Trace.TraceError($"SearchAndPlaceBranchERROR: Cannot find enough neighbour atoms due to {ex2.ToString()}");
                            throw new CDKException($"SearchAndPlaceBranchERROR: Cannot find enough neighbour atoms: {ex2.Message}", ex2);
                        }
                        branchAtoms.Atoms.Add(atom);
                        connectedAtoms.RemoveAllElements();
                    }
                }
            }//for ac.getAtomCount
            PlaceLinearChains3D(molecule, branchAtoms, ap3d, atlp3d, atomPlacer);
        }
        public override void TestGetPlacedHeavyAtoms_IAtomContainer_IAtom()
        {
            AtomPlacer3D   atmplacer = new AtomPlacer3D();
            IAtomContainer molecule  = TestMoleculeFactory.MakeBenzene();

            for (int j = 0; j < 3; j++)
            {
                (molecule.Atoms[j]).IsPlaced = true;
            }
            IAtomContainer placedAndConnectedTo1 = atmplacer.GetPlacedHeavyAtoms(molecule, molecule.Atoms[1]);
            IAtomContainer placedAndConnectedTo2 = atmplacer.GetPlacedHeavyAtoms(molecule, molecule.Atoms[2]);
            IAtomContainer placedAndConnectedTo4 = atmplacer.GetPlacedHeavyAtoms(molecule, molecule.Atoms[4]);

            Assert.AreEqual(2, placedAndConnectedTo1.Atoms.Count);
            Assert.AreEqual(1, placedAndConnectedTo2.Atoms.Count);
            Assert.AreEqual(0, placedAndConnectedTo4.Atoms.Count);
        }
Esempio n. 3
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);
        }