public override void TestGetPlacedHeavyAtom_IAtomContainer_IAtom_IAtom() { AtomPlacer3D atmplacer = new AtomPlacer3D(); IAtomContainer molecule = TestMoleculeFactory.MakeAlkane(7); for (int j = 0; j < 5; j++) { molecule.Atoms[j].IsPlaced = true; } IAtom atom2 = atmplacer.GetPlacedHeavyAtom(molecule, molecule.Atoms[1], molecule.Atoms[0]); IAtom atom3 = atmplacer.GetPlacedHeavyAtom(molecule, molecule.Atoms[2], molecule.Atoms[1]); IAtom nullAtom = atmplacer.GetPlacedHeavyAtom(molecule, molecule.Atoms[0], molecule.Atoms[1]); Assert.AreEqual(atom2, molecule.Atoms[2]); Assert.AreEqual(atom3, molecule.Atoms[3]); Assert.IsNull(nullAtom); }
/// <summary> /// Layout all aliphatic chains with ZMatrix. /// </summary> /// <param name="startAtoms">AtomContainer of possible start atoms for a chain</param> private void PlaceLinearChains3D(IAtomContainer molecule, IAtomContainer startAtoms, AtomPlacer3D ap3d, AtomTetrahedralLigandPlacer3D atlp3d, AtomPlacer atomPlacer) { //Debug.WriteLine("****** PLACE LINEAR CHAINS ******"); IAtom dihPlacedAtom = null; IAtom thirdPlacedAtom = null; IAtomContainer longestUnplacedChain = molecule.Builder.NewAtomContainer(); if (startAtoms.Atoms.Count == 0) { //no branch points ->linear chain //Debug.WriteLine("------ LINEAR CHAIN - FINISH ------"); } else { for (int i = 0; i < startAtoms.Atoms.Count; i++) { //Debug.WriteLine("FOUND BRANCHED ALKAN"); //Debug.WriteLine("Atom NOT NULL:" + molecule.Atoms.IndexOf(startAtoms.GetAtomAt(i))); thirdPlacedAtom = ap3d.GetPlacedHeavyAtom(molecule, startAtoms.Atoms[i]); dihPlacedAtom = ap3d.GetPlacedHeavyAtom(molecule, thirdPlacedAtom, startAtoms.Atoms[i]); longestUnplacedChain.Atoms.Add(dihPlacedAtom); longestUnplacedChain.Atoms.Add(thirdPlacedAtom); longestUnplacedChain.Atoms.Add(startAtoms.Atoms[i]); longestUnplacedChain.Add(AtomPlacer.GetLongestUnplacedChain(molecule, startAtoms.Atoms[i])); SetAtomsToUnVisited(molecule); if (longestUnplacedChain.Atoms.Count < 4) { //di,third,sec //Debug.WriteLine("------ Single BRANCH METHYLTYP ------"); //break; } else { //Debug.WriteLine("LongestUnchainLength:"+longestUnplacedChain.Atoms.Count); ap3d.PlaceAliphaticHeavyChain(molecule, longestUnplacedChain); ap3d.ZMatrixChainToCartesian(molecule, true); SearchAndPlaceBranches(molecule, longestUnplacedChain, ap3d, atlp3d, atomPlacer); } longestUnplacedChain.RemoveAllElements(); }//for } //Debug.WriteLine("****** HANDLE ALIPHATICS END ******"); }
public override void TestGetPlacedHeavyAtom_IAtomContainer_IAtom() { AtomPlacer3D atmplacer = new AtomPlacer3D(); IAtomContainer molecule = TestMoleculeFactory.MakeCyclohexane(); // For(IAtom a : m.Atoms) a.IsPlaced = true; for (int i = 0; i < 3; i++) { molecule.Atoms[i].IsPlaced = true; } IAtom atom1 = atmplacer.GetPlacedHeavyAtom(molecule, molecule.Atoms[0]); Assert.AreEqual(atom1, molecule.Atoms[1]); IAtom atom2 = atmplacer.GetPlacedHeavyAtom(molecule, molecule.Atoms[2]); Assert.AreEqual(atom2, molecule.Atoms[1]); IAtom atom3 = atmplacer.GetPlacedHeavyAtom(molecule, molecule.Atoms[4]); Assert.IsNull(atom3); }
/// <summary> /// Sets a branch atom to a ring or aliphatic chain. /// </summary> /// <param name="unplacedAtom">The new branchAtom</param> /// <param name="atomA">placed atom to which the unplaced atom is connected</param> /// <param name="atomNeighbours">placed atomNeighbours of atomA</param> private static void SetBranchAtom(IAtomContainer molecule, IAtom unplacedAtom, IAtom atomA, IAtomContainer atomNeighbours, AtomPlacer3D ap3d, AtomTetrahedralLigandPlacer3D atlp3d) { //Debug.WriteLine("****** SET Branch Atom ****** >"+molecule.Atoms.IndexOf(unplacedAtom)); IAtomContainer noCoords = molecule.Builder.NewAtomContainer(); noCoords.Atoms.Add(unplacedAtom); Vector3 centerPlacedMolecule = ap3d.GeometricCenterAllPlacedAtoms(molecule); IAtom atomB = atomNeighbours.Atoms[0]; string atypeNameA = atomA.AtomTypeName; string atypeNameB = atomB.AtomTypeName; string atypeNameUnplaced = unplacedAtom.AtomTypeName; double length = ap3d.GetBondLengthValue(atypeNameA, atypeNameUnplaced); double angle = (ap3d.GetAngleValue(atypeNameB, atypeNameA, atypeNameUnplaced)) * Math.PI / 180; // Console.Out.WriteLine("A:"+atomA.Symbol+" "+atomA.AtomTypeName+ // " B:"+atomB.Symbol+" "+atomB.AtomTypeName // +" unplaced Atom:" // +unplacedAtom.AtomTypeName+" BL:"+length+" Angle:"+angle // +" FormalNeighbour:" // +atomA.FormalNeighbourCount+" HYB:"+atomA.getFlag // (CDKConstants.HYBRIDIZATION_SP2) // +" #Neigbhours:"+atomNeighbours.Atoms.Count); IAtom atomC = ap3d.GetPlacedHeavyAtom(molecule, atomB, atomA); Vector3[] branchPoints = atlp3d.Get3DCoordinatesForLigands(atomA, noCoords, atomNeighbours, atomC, (atomA.FormalNeighbourCount.Value - atomNeighbours.Atoms.Count), length, angle); double distance = 0; int farthestPoint = 0; for (int i = 0; i < branchPoints.Length; i++) { if (Math.Abs(Vector3.Distance(branchPoints[i], centerPlacedMolecule)) > Math.Abs(distance)) { distance = Vector3.Distance(branchPoints[i], centerPlacedMolecule); farthestPoint = i; } } int stereo = -1; IBond unplacedBond = molecule.GetBond(atomA, unplacedAtom); if (atomA.StereoParity != 0 || (unplacedBond.Stereo == BondStereo.Up || unplacedBond.Stereo == BondStereo.Down) && molecule.GetMaximumBondOrder(atomA) == BondOrder.Single) { if (atomNeighbours.Atoms.Count > 1) { stereo = AtomTetrahedralLigandPlacer3D.MakeStereocenter(atomA.Point3D.Value, molecule.GetBond(atomA, unplacedAtom), (atomNeighbours.Atoms[0]).Point3D.Value, (atomNeighbours.Atoms[1]).Point3D.Value, branchPoints); } } if (stereo != -1) { farthestPoint = stereo; } unplacedAtom.Point3D = branchPoints[farthestPoint]; unplacedAtom.IsPlaced = true; }