// minimum details /// <summary> Partitions a RingSet into RingSets of connected rings. Rings which share /// an Atom, a Bond or three or more atoms with at least on other ring in /// the RingSet are considered connected. /// /// </summary> /// <param name="ringSet"> The RingSet to be partitioned /// </param> /// <returns> A Vector of connected RingSets /// </returns> public static System.Collections.ArrayList partitionRings(IRingSet ringSet) { System.Collections.ArrayList ringSets = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); if (ringSet.AtomContainerCount == 0) return ringSets; IRingSet tempRingSet = null; IRing ring = (IRing)ringSet.getAtomContainer(0); if (ring == null) return ringSets; IRingSet rs = ring.Builder.newRingSet(); for (int f = 0; f < ringSet.AtomContainerCount; f++) { rs.addAtomContainer(ringSet.getAtomContainer(f)); } do { ring = (IRing)rs.getAtomContainer(0); IRingSet newRs = ring.Builder.newRingSet(); newRs.addAtomContainer(ring); tempRingSet = walkRingSystem(rs, ring, newRs); if (debug) { System.Console.Out.WriteLine("found ringset with ringcount: " + tempRingSet.AtomContainerCount); } ringSets.Add(walkRingSystem(rs, ring, newRs)); } while (rs.AtomContainerCount > 0); return ringSets; }
/// <summary> Returns all the atoms and bonds from all the rings in the RingSet /// in one AtomContainer. /// /// </summary> /// <returns> an AtomContainer with all atoms and bonds from the RingSet /// /// </returns> /// <deprecated> This method has a serious performace impact. Try to use /// other methods. /// </deprecated> public static IAtomContainer getAllInOneContainer(IRingSet ringSet) { // FIXME: make RingSet a subclass of IChemObject (see bug #) and clean up // the code in the next line IAtomContainer container = ringSet.Builder.newAtomContainer(); for (int i = 0; i < ringSet.AtomContainerCount; i++) { container.add((IRing)ringSet.getAtomContainer(i)); } return container; }
private static bool InRingSet(IAtom atom, IRingSet ringSet) { for (int i = 0; i < ringSet.Count; i++) { var ring = (IRing)ringSet[i]; if (ring.Contains(atom)) { return(true); } } return(false); }
/// <summary> /// Checks if <paramref name="atom1"/> and <paramref name="atom2"/> share membership in the same ring or ring system. /// Membership in the same ring is checked if the RingSet contains the SSSR of a molecule; membership in /// the same ring or same ring system is checked if the RingSet contains all rings of a molecule. /// </summary> /// <remarks> /// <note type="important"> /// This method only returns meaningful results if <paramref name="atom1"/> and /// <paramref name="atom2"/> are members of the same molecule for which the ring set was calculated! /// </note> /// </remarks> /// <param name="ringSet">The collection of rings</param> /// <param name="atom1">The first atom</param> /// <param name="atom2">The second atom</param> /// <returns><see langword="true"/> if <paramref name="atom1"/> and <paramref name="atom2"/> share membership of at least one ring or ring system, false otherwise</returns> public static bool IsSameRing(IRingSet ringSet, IAtom atom1, IAtom atom2) { foreach (var atomContainer in ringSet) { IRing ring = (IRing)atomContainer; if (ring.Contains(atom1) && ring.Contains(atom2)) { return(true); } } return(false); }
/// <summary> /// Gets the ringSetOfAtom attribute of the ModelBuilder3D object. /// </summary> /// <returns>The ringSetOfAtom value</returns> private static IRingSet GetRingSetOfAtom(IReadOnlyList <IRingSet> ringSystems, IAtom atom) { IRingSet ringSetOfAtom = null; for (int i = 0; i < ringSystems.Count; i++) { if (((IRingSet)ringSystems[i]).Contains(atom)) { return((IRingSet)ringSystems[i]); } } return(ringSetOfAtom); }
public override void TestClone() { IRingSet ringset = (IRingSet)NewChemObject(); IRing ring = ringset.Builder.NewRing(); ringset.Add(ring); IRingSet clone = (IRingSet)ringset.Clone(); Assert.IsNotNull(clone); Assert.IsTrue(clone is IRingSet); Assert.AreEqual(1, clone.Count); Assert.AreNotSame(ring, clone[0]); }
/// <summary> /// Stores an IRingSet corresponding to a AtomContainer using the bond numbers. /// </summary> /// <param name="mol">The IAtomContainer for which to store the IRingSet.</param> /// <param name="ringSet">The IRingSet to store</param> private void StoreRingSystem(IAtomContainer mol, IRingSet ringSet) { listOfRings = new List <int[]>(); // this is a list of int arrays for (int r = 0; r < ringSet.Count; ++r) { var ring = ringSet[r]; var bondNumbers = new int[ring.Bonds.Count]; for (int i = 0; i < ring.Bonds.Count; ++i) { bondNumbers[i] = mol.Bonds.IndexOf(ring.Bonds[i]); } listOfRings.Add(bondNumbers); } }
public virtual void TestGetRings_IBond() { IRingSet ringset = (IRingSet)NewChemObject(); IAtom ring1Atom1 = ringset.Builder.NewAtom("C"); // rather artificial molecule IAtom ring1Atom2 = ringset.Builder.NewAtom("C"); IAtom sharedAtom1 = ringset.Builder.NewAtom("C"); IAtom sharedAtom2 = ringset.Builder.NewAtom("C"); IAtom ring2Atom1 = ringset.Builder.NewAtom("C"); IAtom ring2Atom2 = ringset.Builder.NewAtom("C"); IBond ring1Bond1 = ringset.Builder.NewBond(ring1Atom1, ring1Atom2); IBond ring1Bond2 = ringset.Builder.NewBond(sharedAtom1, ring1Atom1); IBond ring1Bond3 = ringset.Builder.NewBond(sharedAtom2, ring1Atom2); IBond sharedBond = ringset.Builder.NewBond(sharedAtom1, sharedAtom2); IBond ring2Bond1 = ringset.Builder.NewBond(ring2Atom1, ring2Atom2); IBond ring2Bond2 = ringset.Builder.NewBond(sharedAtom1, ring2Atom1); IBond ring2Bond3 = ringset.Builder.NewBond(sharedAtom2, ring2Atom2); IRing ring1 = ringset.Builder.NewRing(); ring1.Atoms.Add(ring1Atom1); ring1.Atoms.Add(ring1Atom2); ring1.Atoms.Add(sharedAtom1); ring1.Atoms.Add(sharedAtom2); ring1.Bonds.Add(ring1Bond1); ring1.Bonds.Add(ring1Bond2); ring1.Bonds.Add(ring1Bond3); ring1.Bonds.Add(sharedBond); IRing ring2 = ringset.Builder.NewRing(); ring2.Atoms.Add(ring2Atom1); ring2.Atoms.Add(ring2Atom2); ring2.Atoms.Add(sharedAtom1); ring2.Atoms.Add(sharedAtom2); ring2.Bonds.Add(ring2Bond1); ring2.Bonds.Add(ring2Bond2); ring2.Bonds.Add(ring2Bond3); ring2.Bonds.Add(sharedBond); ringset.Add(ring1); ringset.Add(ring2); Assert.AreEqual(1, ringset.GetRings(ring1Bond1).Count()); Assert.AreEqual(1, ringset.GetRings(ring1Bond2).Count()); Assert.AreEqual(1, ringset.GetRings(ring1Bond3).Count()); Assert.AreEqual(2, ringset.GetRings(sharedBond).Count()); Assert.AreEqual(1, ringset.GetRings(ring2Bond1).Count()); Assert.AreEqual(1, ringset.GetRings(ring2Bond2).Count()); Assert.AreEqual(1, ringset.GetRings(ring2Bond3).Count()); }
/// <summary> /// The basic rings of the spanning tree. Using the pruned edges, return any path /// which connects the end points of the pruned edge in the tree. These paths form /// cycles. /// </summary> /// <returns>basic rings</returns> /// <exception cref="NoSuchAtomException">atoms not found in the molecule</exception> public IRingSet GetBasicRings() { IRingSet ringset = molecule.Builder.NewRingSet(); IAtomContainer spt = GetSpanningTree(); for (int i = 0; i < totalEdgeCount; i++) { if (!bondsInTree[i]) { ringset.Add(GetRing(spt, molecule.Bonds[i])); } } return(ringset); }
public void TestGetBondCount() { IAtomContainer mol = TestMoleculeFactory.MakeAdenine(); AllRingsFinder arf = new AllRingsFinder(); IRingSet ringSet = arf.FindAllRings(mol); Assert.AreEqual(3, ringSet.Count); Assert.AreEqual(20, RingSetManipulator.GetBondCount(ringSet)); mol = TestMoleculeFactory.MakeBiphenyl(); ringSet = arf.FindAllRings(mol); Assert.AreEqual(2, ringSet.Count); Assert.AreEqual(12, RingSetManipulator.GetBondCount(ringSet)); }
/// <summary> Finds the Set of Relevant Rings. /// These rings are contained in everry possible SSSR. /// The returned set is uniquely defined. /// /// </summary> /// <returns> a RingSet containing the Relevant Rings /// </returns> public virtual IRingSet findRelevantRings() { if (atomContainer == null) { return(null); } IRingSet ringSet = toRingSet(atomContainer, cycleBasis().cycles()); atomContainer.setProperty(CDKConstants.RELEVANT_RINGS, ringSet); //UPGRADE_TODO: Method 'java.util.Map.keySet' was converted to 'CSGraphT.SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilMapkeySet'" return(toRingSet(atomContainer, new CSGraphT.SupportClass.HashSetSupport(cycleBasis().relevantCycles().Keys))); }
public virtual void TestContains_IAtom() { IRingSet ringset = (IRingSet)NewChemObject(); IAtom ring1Atom1 = ringset.Builder.NewAtom("C"); // rather artificial molecule IAtom ring1Atom2 = ringset.Builder.NewAtom("C"); IAtom sharedAtom1 = ringset.Builder.NewAtom("C"); IAtom sharedAtom2 = ringset.Builder.NewAtom("C"); IAtom ring2Atom1 = ringset.Builder.NewAtom("C"); IAtom ring2Atom2 = ringset.Builder.NewAtom("C"); IBond ring1Bond1 = ringset.Builder.NewBond(ring1Atom1, ring1Atom2); IBond ring1Bond2 = ringset.Builder.NewBond(sharedAtom1, ring1Atom1); IBond ring1Bond3 = ringset.Builder.NewBond(sharedAtom2, ring1Atom2); IBond sharedBond = ringset.Builder.NewBond(sharedAtom1, sharedAtom2); IBond ring2Bond1 = ringset.Builder.NewBond(ring2Atom1, ring2Atom2); IBond ring2Bond2 = ringset.Builder.NewBond(sharedAtom1, ring2Atom1); IBond ring2Bond3 = ringset.Builder.NewBond(sharedAtom2, ring2Atom2); IRing ring1 = ringset.Builder.NewRing(); ring1.Atoms.Add(ring1Atom1); ring1.Atoms.Add(ring1Atom2); ring1.Atoms.Add(sharedAtom1); ring1.Atoms.Add(sharedAtom2); ring1.Bonds.Add(ring1Bond1); ring1.Bonds.Add(ring1Bond2); ring1.Bonds.Add(ring1Bond3); ring1.Bonds.Add(sharedBond); IRing ring2 = ringset.Builder.NewRing(); ring2.Atoms.Add(ring2Atom1); ring2.Atoms.Add(ring2Atom2); ring2.Atoms.Add(sharedAtom1); ring2.Atoms.Add(sharedAtom2); ring2.Bonds.Add(ring2Bond1); ring2.Bonds.Add(ring2Bond2); ring2.Bonds.Add(ring2Bond3); ring2.Bonds.Add(sharedBond); ringset.Add(ring1); ringset.Add(ring2); Assert.IsTrue(ringset.Contains(ring1Atom1)); Assert.IsTrue(ringset.Contains(ring1Atom2)); Assert.IsTrue(ringset.Contains(sharedAtom1)); Assert.IsTrue(ringset.Contains(sharedAtom2)); Assert.IsTrue(ringset.Contains(ring2Atom1)); Assert.IsTrue(ringset.Contains(ring2Atom2)); }
public void TestBigRingSystem_MaxRingSize6_03419() { IRingSet ringSet = null; AllRingsFinder arf = new AllRingsFinder(); var filename = "NCDK.Data.MDL.ring_03419.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins); var chemFile = reader.Read(builder.NewChemFile()); var seq = chemFile[0]; var model = seq[0]; IAtomContainer molecule = model.MoleculeSet[0]; ringSet = arf.FindAllRings(molecule, 6); Assert.AreEqual(12, ringSet.Count); }
IRingSet GetRings() { IRingSet rs = null; try { AllRingsFinder arf = new AllRingsFinder(); rs = arf.FindAllRings(mol); } catch (Exception e) { Console.Out.WriteLine("Could not find all rings: " + e.Message); } return(rs); }
public void TestCholoylCoA() { IRingSet ringSet = null; AllRingsFinder arf = new AllRingsFinder(); var filename = "NCDK.Data.MDL.choloylcoa.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins); var chemFile = reader.Read(builder.NewChemFile()); var seq = chemFile[0]; var model = seq[0]; IAtomContainer molecule = model.MoleculeSet[0]; ringSet = arf.FindAllRings(molecule); Assert.AreEqual(14, ringSet.Count); }
/// <summary> We define the heaviest ring as the one with the highest number of double bonds. /// Needed for example for the placement of in-ring double bonds. /// /// </summary> /// <param name="bond"> A bond which must be contained by the heaviest ring /// </param> /// <returns> The ring with the higest number of double bonds connected to a given bond /// </returns> public static IRing getHeaviestRing(IRingSet ringSet, IBond bond) { System.Collections.IList rings = ringSet.getRings(bond); IRing ring = null; int maxOrderSum = 0; for (int i = 0; i < rings.Count; i++) { if (maxOrderSum < ((IRing)rings[i]).OrderSum) { ring = (IRing)rings[i]; maxOrderSum = ring.OrderSum; } } return(ring); }
/// <summary> Checks if <code>atom1</code> and <code>atom2</code> share membership in the same ring or ring system. /// Membership in the same ring is checked if the RingSet contains the SSSR of a molecule; membership in /// the same ring or same ring system is checked if the RingSet contains all rings of a molecule.<BR><BR> /// /// <p><B>Important:</B> This method only returns meaningful results if <code>atom1</code> and /// <code>atom2</code> are members of the same molecule for which the RingSet was calculated! /// /// </summary> /// <param name="atom1"> The first atom /// </param> /// <param name="atom2"> The second atom /// </param> /// <returns> boolean true if <code>atom1</code> and <code>atom2</code> share membership of at least one ring or ring system, false otherwise /// </returns> public static bool isSameRing(IRingSet ringSet, IAtom atom1, IAtom atom2) { IAtomContainer[] rings = ringSet.AtomContainers; for (int i = 0; i < rings.Length; i++) { IRing ring = (IRing)rings[i]; if (ring.contains(atom1)) { if (ring.contains(atom2)) { return(true); } } } return(false); }
public virtual void TestStateChanged_EventPropagation_RingSet() { ChemObjectListenerImpl listener = new ChemObjectListenerImpl(); IChemModel chemObject = (IChemModel)NewChemObject(); chemObject.Listeners.Add(listener); IRingSet ringSet = chemObject.Builder.NewRingSet(); chemObject.RingSet = ringSet; Assert.IsTrue(listener.Changed); // reset the listener listener.Reset(); Assert.IsFalse(listener.Changed); // changing the set should trigger a change event in the IChemModel ringSet.Add(chemObject.Builder.NewRing()); Assert.IsTrue(listener.Changed); }
/// <summary> /// We define the heaviest ring as the one with the highest number of double bonds. /// Needed for example for the placement of in-ring double bonds. /// </summary> /// <param name="ringSet">The collection of rings</param> /// <param name="bond">A bond which must be contained by the heaviest ring</param> /// <returns>The ring with the highest number of double bonds connected to a given bond</returns> public static IRing GetHeaviestRing(IRingSet ringSet, IBond bond) { var rings = ringSet.GetRings(bond); IRing ring = null; int maxOrderSum = 0; foreach (var ring1 in rings) { if (maxOrderSum < ((IRing)ring1).GetBondOrderSum()) { ring = (IRing)ring1; maxOrderSum = ring.GetBondOrderSum(); } } return(ring); }
public virtual void TestAdd_IRingSet() { IRingSet rs = (IRingSet)NewChemObject(); IRing r1 = rs.Builder.NewRing(5, "C"); IRing r2 = rs.Builder.NewRing(3, "C"); rs.Add(r1); IRingSet rs2 = (IRingSet)NewChemObject(); rs2.Add(r2); rs2.Add(rs); Assert.AreEqual(1, rs.Count); Assert.AreEqual(2, rs2.Count); }
public void TestIsEmpty_RingSet() { var model = (IChemModel)NewChemObject(); IChemObjectBuilder builder = model.Builder; IRing container = builder.NewRing(); // NCDK does not allow to add Ring to RingSet IRingSet ringset = builder.NewRingSet(); Assert.IsTrue(model.IsEmpty()); model.RingSet = ringset; Assert.IsTrue(model.IsEmpty()); ringset.Add(container); Assert.IsFalse(model.IsEmpty()); model.RingSet = null; Assert.IsTrue(model.IsEmpty()); }
public void TestGetAtomCount_IRingSet() { IRingSet rs = builder.NewRingSet(); IRing ac1 = builder.NewRing(); ac1.Atoms.Add(builder.NewAtom("O")); rs.Add(ac1); IRing ac2 = builder.NewRing(); ac2.Atoms.Add(builder.NewAtom("C")); ac2.Atoms.Add(builder.NewAtom("C")); ac2.AddBond(ac2.Atoms[0], ac2.Atoms[1], BondOrder.Double); rs.Add(ac2); Assert.AreEqual(3, RingSetManipulator.GetAtomCount(rs)); Assert.AreEqual(1, RingSetManipulator.GetBondCount(rs)); }
public void TestBigRingSystem_MaxRingSize4_fourRing5x10() { IRingSet ringSet = null; AllRingsFinder arf = new AllRingsFinder(); var filename = "NCDK.Data.MDL.four-ring-5x10.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins); var chemFile = reader.Read(builder.NewChemFile()); var seq = chemFile[0]; var model = seq[0]; IAtomContainer molecule = model.MoleculeSet[0]; // there are 5x10 squares (four-rings) in the 5x10 molecule ringSet = arf.FindAllRings(molecule, 4); Assert.AreEqual(50, ringSet.Count); }
private static double GetRingMatch(IRingSet rings, List <IAtom> atoms) { double score = 0.0; foreach (var a in atoms) { foreach (var ring in rings) { if (ring.Contains(a)) { score += 10; } } } return(score); }
/// <summary> /// Stores an <see cref="IRingSet"/> corresponding to a molecule using the bond numbers. /// </summary> /// <param name="mol">The IAtomContainer for which to store the IRingSet.</param> /// <param name="ringSet">The IRingSet to store</param> /// <returns>The List of int arrays for the bond numbers of each ringSet</returns> private static List <int[]> GetRingSystem(IAtomContainer mol, IRingSet ringSet) { List <int[]> bondsArray; bondsArray = new List <int[]>(); for (int r = 0; r < ringSet.Count; ++r) { IRing ring = (IRing)ringSet[r]; int[] bondNumbers = new int[ring.Bonds.Count]; for (int i = 0; i < ring.Bonds.Count; ++i) { bondNumbers[i] = mol.Bonds.IndexOf(ring.Bonds[i]); } bondsArray.Add(bondNumbers); } return(bondsArray); }
/// <summary> Returns the ring with the highest numbers of other rings attached to it. /// /// </summary> /// <returns> the ring with the highest numbers of other rings attached to it. /// </returns> public static IRing getMostComplexRing(IRingSet ringSet) { int[] neighbors = new int[ringSet.AtomContainerCount]; IRing ring1, ring2; IAtom atom1, atom2; int mostComplex = 0, mostComplexPosition = 0; /* for all rings in this RingSet */ for (int i = 0; i < ringSet.AtomContainerCount; i++) { /* Take each ring */ ring1 = (IRing)ringSet.getAtomContainer(i); /* look at each Atom in this ring whether it is part of any other ring */ for (int j = 0; j < ring1.AtomCount; j++) { atom1 = ring1.getAtomAt(j); /* Look at each of the other rings in the ringset */ for (int k = i + 1; k < ringSet.AtomContainerCount; k++) { ring2 = (IRing)ringSet.getAtomContainer(k); if (ring1 != ring2) { for (int l = 0; l < ring2.AtomCount; l++) { atom2 = ring2.getAtomAt(l); if (atom1 == atom2) { neighbors[i]++; neighbors[k]++; break; } } } } } } for (int i = 0; i < neighbors.Length; i++) { if (neighbors[i] > mostComplex) { mostComplex = neighbors[i]; mostComplexPosition = i; } } return((IRing)ringSet.getAtomContainer(mostComplexPosition)); }
private static bool[] FindRingsToCheck(IRingSet rs) { var Check = new bool[rs.Count]; for (int i = 0; i <= Check.Length - 1; i++) { Check[i] = true; } for (int i = 0; i <= rs.Count - 1; i++) { var r = rs[i]; if (r.Atoms.Count > 7) { Check[i] = false; continue; } int NonSP2Count = 0; for (int j = 0; j <= r.Atoms.Count - 1; j++) { if (r.Atoms[j].Hybridization.IsUnset() || r.Atoms[j].Hybridization != Hybridization.SP2) { NonSP2Count++; if (r.Atoms[j].AtomicNumber.Equals(AtomicNumbers.C)) { Check[i] = false; goto iloop; } } } if (NonSP2Count > 1) { Check[i] = false; continue; } iloop: ; } return(Check); }
/// <summary> /// Perform a walk in the given RingSet, starting at a given Ring and /// recursively searching for other Rings connected to this ring. By doing /// this it finds all rings in the RingSet connected to the start ring, /// putting them in newRs, and removing them from rs. /// </summary> /// <param name="rs">The RingSet to be searched</param> /// <param name="ring">The ring to start with</param> /// <param name="newRs">The RingSet containing all Rings connected to ring</param> /// <returns>newRs The RingSet containing all Rings connected to ring</returns> private static IRingSet WalkRingSystem(IRingSet rs, IRing ring, IRingSet newRs) { IRing tempRing; var tempRings = rs.GetConnectedRings(ring); rs.Remove(ring); foreach (var container in tempRings) { tempRing = (IRing)container; if (!newRs.Contains(tempRing)) { newRs.Add(tempRing); newRs.Add(WalkRingSystem(rs, tempRing, newRs)); } } return(newRs); }
public void TestBigRingSystem() { IRingSet ringSet = null; AllRingsFinder arf = AllRingsFinder.UsingThreshold(Threshold.PubChem994); var filename = "NCDK.Data.MDL.ring_03419.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins); var chemFile = reader.Read(builder.NewChemFile()); var seq = chemFile[0]; var model = seq[0]; IAtomContainer molecule = model.MoleculeSet[0]; ringSet = arf.FindAllRings(molecule); // the 1976 value was empirically derived, and might not be accurate Assert.AreEqual(1976, ringSet.Count); }
/// <summary> /// Returns the largest (number of atoms) ring set in a molecule. /// </summary> /// <param name="ringSystems">RingSystems of a molecule</param> /// <returns>The largestRingSet</returns> public static IRingSet GetLargestRingSet(IEnumerable <IRingSet> ringSystems) { IRingSet largestRingSet = null; int atomNumber = 0; IAtomContainer container = null; foreach (var ringSystem in ringSystems) { container = GetAllInOneContainer(ringSystem); if (atomNumber < container.Atoms.Count) { atomNumber = container.Atoms.Count; largestRingSet = ringSystem; } } return(largestRingSet); }
/// <summary> /// Positions the aliphatic substituents of a ring system /// </summary> /// <param name="rs">The RingSystem for which the substituents are to be laid out</param> /// <returns>A list of atoms that where laid out</returns> public IAtomContainer PlaceRingSubstituents(IRingSet rs, double bondLength) { Debug.WriteLine("RingPlacer.PlaceRingSubstituents() start"); IRing ring = null; IAtom atom = null; IAtomContainer unplacedPartners = rs.Builder.NewAtomContainer(); IAtomContainer sharedAtoms = rs.Builder.NewAtomContainer(); IAtomContainer primaryAtoms = rs.Builder.NewAtomContainer(); IAtomContainer treatedAtoms = rs.Builder.NewAtomContainer(); for (int j = 0; j < rs.Count; j++) { ring = (IRing)rs[j]; // Get the j-th Ring in RingSet rs for (int k = 0; k < ring.Atoms.Count; k++) { unplacedPartners.RemoveAllElements(); sharedAtoms.RemoveAllElements(); primaryAtoms.RemoveAllElements(); atom = ring.Atoms[k]; var rings = rs.GetRings(atom); var centerOfRingGravity = GeometryUtil.Get2DCenter(rings); AtomPlacer.PartitionPartners(atom, unplacedPartners, sharedAtoms); AtomPlacer.MarkNotPlaced(unplacedPartners); try { for (int f = 0; f < unplacedPartners.Atoms.Count; f++) { Debug.WriteLine("placeRingSubstituents->unplacedPartners: " + (Molecule.Atoms.IndexOf(unplacedPartners.Atoms[f]) + 1)); } } catch (Exception) { } treatedAtoms.Add(unplacedPartners); if (unplacedPartners.Atoms.Count > 0) { AtomPlacer.DistributePartners(atom, sharedAtoms, centerOfRingGravity, unplacedPartners, bondLength); } } } Debug.WriteLine("RingPlacer.PlaceRingSubstituents() end"); return(treatedAtoms); }
/// <summary> Sorts the rings in the set by size. The largest ring comes /// first. /// </summary> public static void sort(IRingSet ringSet) { System.Collections.IList ringList = new System.Collections.ArrayList(); IAtomContainer[] rings = ringSet.AtomContainers; for (int i = 0; i < rings.Length; i++) { ringList.Add(rings[i]); } SupportClass.CollectionsSupport.Sort(ringList, new RingSizeComparator(RingSizeComparator.LARGE_FIRST)); ringSet.removeAllAtomContainers(); System.Collections.IEnumerator iter = ringList.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" while (iter.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'" ringSet.addAtomContainer((IRing)iter.Current); } }
private bool preprocessMolecule(IAtomContainer original) { //prepare atom weights var atomWeightCanBeCalculated = prepareAtomWeights(original); // If the SDF contains an "R" or something, we don't know its mass, so this whole endevour is fruitless // (since we won't be able to match the fragment masses to the peaks). if (!atomWeightCanBeCalculated) { return false; } //mark all the bonds and atoms with numbers --> identify them later on originalMolecule = markAllBonds(original); //do ring detection with the original molecule var allRingsFinder = new AllRingsFinder(); // Steve: Set a really large timeout, because we don't want to crash just because it took a long time. // The size limit of 7 below should stop it looping forever. allRingsFinder.setTimeout(int.MaxValue); // TODO: Steve: The 7 is a max ring size - I added this to prevent it getting in to infinite loops (7 comes from MetFrag // where it is used in some other random class). Don't know if we need to change this?? allRings = allRingsFinder.findAllRings(originalMolecule, Integer.valueOf(7)); aromaticBonds = new List<IBond>(); CDKHueckelAromaticityDetector.detectAromaticity(originalMolecule); foreach (var bond in originalMolecule.bonds().ToWindowsEnumerable<IBond>()) { //lets see if it is a ring and aromatic var rings = allRings.getRings(bond); //don't split up aromatic rings...see constructor for option for (var i = 0; i < rings.getAtomContainerCount(); i++) { var aromatic = AromaticityCalculator.isAromatic((IRing)rings.getAtomContainer(i), originalMolecule); if (aromatic) { aromaticBonds.Add(bond); break; } } } return true; }
/// <summary> Description of the Method /// /// </summary> /// <param name="ac"> The AtomContainer to be searched /// </param> /// <param name="pathes"> A vectoring storing all the pathes /// </param> /// <param name="ringSet"> A ringset to be extended while we search /// </param> /// <exception cref="CDKException"> An exception thrown if something goes wrong or if the timeout limit is reached /// </exception> private void doSearch(IAtomContainer ac, System.Collections.ArrayList pathes, IRingSet ringSet) { IAtom atom = null; /* * First we convert the molecular graph into a a path graph by * creating a set of two membered pathes from all the bonds in the molecule */ initPathGraph(ac, pathes); if (debug) { System.Console.Out.WriteLine("BondCount: " + ac.getBondCount() + ", PathCount: " + pathes.Count); } do { atom = selectAtom(ac); if (atom != null) { remove(atom, ac, pathes, ringSet); } } while (pathes.Count > 0 && atom != null); if (debug) { System.Console.Out.WriteLine("pathes.size(): " + pathes.Count); } if (debug) { System.Console.Out.WriteLine("ringSet.size(): " + ringSet.AtomContainerCount); } }
/// <summary> Removes an atom from the AtomContainer under certain conditions. /// See {@cdk.cite HAN96} for details /// /// /// </summary> /// <param name="atom"> The atom to be removed /// </param> /// <param name="ac"> The AtomContainer to work on /// </param> /// <param name="pathes"> The pathes to manipulate /// </param> /// <param name="rings"> The ringset to be extended /// </param> /// <exception cref="CDKException"> Thrown if something goes wrong or if the timeout is exceeded /// </exception> private void remove(IAtom atom, IAtomContainer ac, System.Collections.ArrayList pathes, IRingSet rings) { Path path1 = null; Path path2 = null; Path union = null; int intersectionSize = 0; newPathes.Clear(); removePathes.Clear(); potentialRings.Clear(); if (debug) { System.Console.Out.WriteLine("*** Removing atom " + originalAc.getAtomNumber(atom) + " ***"); } for (int i = 0; i < pathes.Count; i++) { path1 = (Path)pathes[i]; if (path1[0] == atom || path1[path1.Count - 1] == atom) { for (int j = i + 1; j < pathes.Count; j++) { //System.out.print("."); path2 = (Path)pathes[j]; if (path2[0] == atom || path2[path2.Count - 1] == atom) { intersectionSize = path1.getIntersectionSize(path2); if (intersectionSize < 3) { //if (debug) System.out.println("Joining " + path1.toString(originalAc) + " and " + path2.toString(originalAc)); union = Path.join(path1, path2, atom); if (intersectionSize == 1) { newPathes.Add(union); } else { potentialRings.Add(union); } //if (debug) System.out.println("Intersection Size: " + intersectionSize); //if (debug) System.out.println("Union: " + union.toString(originalAc)); /* * Now we know that path1 and * path2 share the Atom atom. */ removePathes.Add(path1); removePathes.Add(path2); } } checkTimeout(); } } } for (int f = 0; f < removePathes.Count; f++) { pathes.Remove(removePathes[f]); } for (int f = 0; f < newPathes.Count; f++) { pathes.Add(newPathes[f]); } detectRings(potentialRings, rings, originalAc); ac.removeAtomAndConnectedElectronContainers(atom); if (debug) { System.Console.Out.WriteLine("\n" + pathes.Count + " pathes and " + ac.AtomCount + " atoms left."); } }
/// <summary> Checks if <code>atom1</code> and <code>atom2</code> share membership in the same ring or ring system. /// Membership in the same ring is checked if the RingSet contains the SSSR of a molecule; membership in /// the same ring or same ring system is checked if the RingSet contains all rings of a molecule.<BR><BR> /// /// <p><B>Important:</B> This method only returns meaningful results if <code>atom1</code> and /// <code>atom2</code> are members of the same molecule for which the RingSet was calculated! /// /// </summary> /// <param name="atom1"> The first atom /// </param> /// <param name="atom2"> The second atom /// </param> /// <returns> boolean true if <code>atom1</code> and <code>atom2</code> share membership of at least one ring or ring system, false otherwise /// </returns> public static bool isSameRing(IRingSet ringSet, IAtom atom1, IAtom atom2) { IAtomContainer[] rings = ringSet.AtomContainers; for (int i = 0; i < rings.Length; i++) { IRing ring = (IRing)rings[i]; if (ring.contains(atom1)) if (ring.contains(atom2)) return true; } return false; }
/// <summary> Returns the ring with the highest numbers of other rings attached to it. /// /// </summary> /// <returns> the ring with the highest numbers of other rings attached to it. /// </returns> public static IRing getMostComplexRing(IRingSet ringSet) { int[] neighbors = new int[ringSet.AtomContainerCount]; IRing ring1, ring2; IAtom atom1, atom2; int mostComplex = 0, mostComplexPosition = 0; /* for all rings in this RingSet */ for (int i = 0; i < ringSet.AtomContainerCount; i++) { /* Take each ring */ ring1 = (IRing)ringSet.getAtomContainer(i); /* look at each Atom in this ring whether it is part of any other ring */ for (int j = 0; j < ring1.AtomCount; j++) { atom1 = ring1.getAtomAt(j); /* Look at each of the other rings in the ringset */ for (int k = i + 1; k < ringSet.AtomContainerCount; k++) { ring2 = (IRing)ringSet.getAtomContainer(k); if (ring1 != ring2) { for (int l = 0; l < ring2.AtomCount; l++) { atom2 = ring2.getAtomAt(l); if (atom1 == atom2) { neighbors[i]++; neighbors[k]++; break; } } } } } } for (int i = 0; i < neighbors.Length; i++) { if (neighbors[i] > mostComplex) { mostComplex = neighbors[i]; mostComplexPosition = i; } } return (IRing)ringSet.getAtomContainer(mostComplexPosition); }
/** * Instantiates a new post processing step. It reads in the neutral loss * table and needs all the aromatic and ring bonds. * * @param original * the original * @param aromaticBonds * the aromatic bonds * @param allRings * the all rings * @throws IOException * @throws NumberFormatException */ public PostProcessor(IRingSet allRings, IDictionary<double, NeutralLoss> neutralLossTable) { allRingsOrig = allRings; neutralLoss = neutralLossTable; }
/// <summary> We define the heaviest ring as the one with the highest number of double bonds. /// Needed for example for the placement of in-ring double bonds. /// /// </summary> /// <param name="bond"> A bond which must be contained by the heaviest ring /// </param> /// <returns> The ring with the higest number of double bonds connected to a given bond /// </returns> public static IRing getHeaviestRing(IRingSet ringSet, IBond bond) { System.Collections.IList rings = ringSet.getRings(bond); IRing ring = null; int maxOrderSum = 0; for (int i = 0; i < rings.Count; i++) { if (maxOrderSum < ((IRing)rings[i]).OrderSum) { ring = (IRing)rings[i]; maxOrderSum = ring.OrderSum; } } return ring; }
/// <summary> Perform a walk in the given RingSet, starting at a given Ring and /// recursivly searching for other Rings connected to this ring. By doing /// this it finds all rings in the RingSet connected to the start ring, /// putting them in newRs, and removing them from rs. /// /// </summary> /// <param name="rs"> The RingSet to be searched /// </param> /// <param name="ring"> The ring to start with /// </param> /// <param name="newRs"> The RingSet containing all Rings connected to ring /// </param> /// <returns> newRs The RingSet containing all Rings connected to ring /// </returns> private static IRingSet walkRingSystem(IRingSet rs, IRing ring, IRingSet newRs) { IRing tempRing; System.Collections.IList tempRings = rs.getConnectedRings(ring); if (debug) { System.Console.Out.WriteLine("walkRingSystem -> tempRings.size(): " + tempRings.Count); } rs.removeAtomContainer(ring); System.Collections.IEnumerator iter = tempRings.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" while (iter.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'" tempRing = (IRing)iter.Current; if (!newRs.contains(tempRing)) { newRs.addAtomContainer(tempRing); newRs.add(walkRingSystem(rs, tempRing, newRs)); } } return newRs; }
/// <summary> Generate canonical SMILES from the <code>molecule</code>. This method /// canonicaly lables the molecule but dose not perform any checks on the /// chemical validity of the molecule. Does not care about multiple molecules. /// IMPORTANT: A precomputed Set of All Rings (SAR) can be passed to this /// SmilesGenerator in order to avoid recomputing it. Use setRings() to /// assign the SAR. /// /// </summary> /// <param name="molecule"> The molecule to evaluate /// </param> /// <param name="chiral"> true=SMILES will be chiral, false=SMILES /// will not be chiral. /// </param> /// <param name="doubleBondConfiguration"> Description of Parameter /// </param> /// <returns> Description of the Returned Value /// </returns> /// <exception cref="CDKException"> At least one atom has no Point2D; /// coordinates are needed for creating the chiral smiles. This excpetion /// can only be thrown if chiral smiles is created, ignore it if you want a /// non-chiral smiles (createSMILES(AtomContainer) does not throw an /// exception). /// </exception> /// <seealso cref="org.openscience.cdk.graph.invariant.CanonicalLabeler.canonLabel(IAtomContainer)"> /// </seealso> //UPGRADE_NOTE: Synchronized keyword was removed from method 'createSMILESWithoutCheckForMultipleMolecules'. Lock expression was added. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1027'" public virtual System.String createSMILESWithoutCheckForMultipleMolecules(IMolecule molecule, bool chiral, bool[] doubleBondConfiguration) { lock (this) { if (molecule.AtomCount == 0) { return ""; } canLabler.canonLabel(molecule); brokenBonds.Clear(); ringMarker = 0; IAtom[] all = molecule.Atoms; IAtom start = null; for (int i = 0; i < all.Length; i++) { IAtom atom = all[i]; if (chiral && atom.getPoint2d() == null) { throw new CDKException("Atom number " + i + " has no 2D coordinates, but 2D coordinates are needed for creating chiral smiles"); } //System.out.println("Setting all VISITED flags to false"); atom.setFlag(CDKConstants.VISITED, false); if ((long)((System.Int64)atom.getProperty("CanonicalLable")) == 1) { start = atom; } } //detect aromaticity if (rings == null) { if (ringFinder == null) { ringFinder = new AllRingsFinder(); } rings = ringFinder.findAllRings(molecule); } HueckelAromaticityDetector.detectAromaticity(molecule, rings, false); if (chiral && rings.AtomContainerCount > 0) { System.Collections.ArrayList v = RingPartitioner.partitionRings(rings); //System.out.println("RingSystems: " + v.size()); for (int i = 0; i < v.Count; i++) { int counter = 0; IAtomContainer allrings = RingSetManipulator.getAllInOneContainer((IRingSet)v[i]); for (int k = 0; k < allrings.AtomCount; k++) { if (!BondTools.isStereo(molecule, allrings.getAtomAt(k)) && hasWedges(molecule, allrings.getAtomAt(k)) != null) { IBond bond = molecule.getBond(allrings.getAtomAt(k), hasWedges(molecule, allrings.getAtomAt(k))); if (bond.Stereo == CDKConstants.STEREO_BOND_UP) { allrings.getAtomAt(k).setProperty(RING_CONFIG, UP); } else { allrings.getAtomAt(k).setProperty(RING_CONFIG, DOWN); } counter++; } } if (counter == 1) { for (int k = 0; k < allrings.AtomCount; k++) { allrings.getAtomAt(k).setProperty(RING_CONFIG, UP); } } } } System.Text.StringBuilder l = new System.Text.StringBuilder(); createSMILES(start, l, molecule, chiral, doubleBondConfiguration); rings = null; return l.ToString(); } }
/// <summary> Retrieves the set of all rings and performs an aromaticity detection based /// on Hueckels 4n + 2 rule. An AllRingsFinder with customized timeout may be /// assigned to this method. /// </summary> /// <param name="removeAromatictyFlags"> When true, we leaves ChemObjects that /// are already marked as aromatic as they are /// </param> /// <param name="atomContainer"> AtomContainer to be searched for /// </param> /// <param name="arf"> AllRingsFinder to be employed for the /// ringsearch. Use this to customize the /// AllRingsFinder timeout feature /// rings /// </param> /// <returns> True, if molecule has aromatic features /// </returns> /// <exception cref="CDKException"> Thrown in case of errors or an /// AllRingsFinder timeout /// </exception> public static bool detectAromaticity(IAtomContainer atomContainer, bool removeAromatictyFlags, AllRingsFinder arf) { //logger.debug("Entered Aromaticity Detection"); //logger.debug("Starting AllRingsFinder"); long before = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; if (arf == null) { arf = new AllRingsFinder(); arf.setTimeout(timeout); } ringSet = arf.findAllRings(atomContainer); long after = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; //logger.debug("time for finding all rings: " + (after - before) + " milliseconds"); //logger.debug("Finished AllRingsFinder"); if (ringSet.AtomContainerCount > 0) { return detectAromaticity(atomContainer, ringSet, removeAromatictyFlags); } return false; }
/// <summary> Uses precomputed set of ALL rings and performs an aromaticity detection /// based on Hueckels 4n + 2 rule. /// /// </summary> /// <param name="ringSet"> set of ALL rings /// </param> /// <param name="removeAromaticityFlags"> Leaves ChemObjects that are already marked as /// aromatic as they are /// </param> /// <param name="atomContainer"> AtomContainer to be searched for rings /// </param> /// <returns> True, if molecules contains an /// aromatic feature /// </returns> public static bool detectAromaticity(IAtomContainer atomContainer, IRingSet ringSet, bool removeAromaticityFlags) { bool foundSomething = false; if (removeAromaticityFlags) { for (int f = 0; f < atomContainer.AtomCount; f++) { atomContainer.getAtomAt(f).setFlag(CDKConstants.ISAROMATIC, false); } for (int f = 0; f < atomContainer.ElectronContainerCount; f++) { IElectronContainer electronContainer = atomContainer.getElectronContainerAt(f); if (electronContainer is IBond) { electronContainer.setFlag(CDKConstants.ISAROMATIC, false); } } for (int f = 0; f < ringSet.AtomContainerCount; f++) { ((IRing)ringSet.getAtomContainer(f)).setFlag(CDKConstants.ISAROMATIC, false); } } IRing ring = null; RingSetManipulator.sort(ringSet); for (int f = 0; f < ringSet.AtomContainerCount; f++) { ring = (IRing)ringSet.getAtomContainer(f); //logger.debug("Testing for aromaticity in ring no ", f); if (AromaticityCalculator.isAromatic(ring, atomContainer)) { ring.setFlag(CDKConstants.ISAROMATIC, true); for (int g = 0; g < ring.AtomCount; g++) { ring.getAtomAt(g).setFlag(CDKConstants.ISAROMATIC, true); } for (int g = 0; g < ring.ElectronContainerCount; g++) { IElectronContainer electronContainer = ring.getElectronContainerAt(g); if (electronContainer is IBond) { electronContainer.setFlag(CDKConstants.ISAROMATIC, true); } } foundSomething = true; //logger.debug("This ring is aromatic: ", f); } else { //logger.debug("This ring is *not* aromatic: ", f); } } return foundSomething; }
/// <summary> Uses precomputed set of ALL rings and performs an aromaticity detection /// based on Hueckels 4n+2 rule. /// /// </summary> /// <param name="ringSet "> set of ALL rings /// </param> /// <param name="atomContainer"> The AtomContainer to detect rings in /// </param> /// <returns> True if molecule has aromatic features /// </returns> /// <exception cref="org.openscience.cdk.exception.CDKException"> /// </exception> public static bool detectAromaticity(IAtomContainer atomContainer, IRingSet ringSet) { return (detectAromaticity(atomContainer, ringSet, true)); }
/// <summary> Converts a RingSet to an AtomContainer. /// /// </summary> /// <param name="ringSet"> The RingSet to be converted. /// </param> /// <returns> The AtomContainer containing the bonds and atoms of the ringSet. /// </returns> public static IAtomContainer convertToAtomContainer(IRingSet ringSet) { IRing ring = (IRing)ringSet.getAtomContainer(0); if (ring == null) return null; IAtomContainer ac = ring.Builder.newAtomContainer(); for (int i = 0; i < ringSet.AtomContainerCount; i++) { ring = (IRing)ringSet.getAtomContainer(i); for (int r = 0; r < ring.getBondCount(); r++) { IBond bond = ring.getBondAt(r); if (!ac.contains(bond)) { for (int j = 0; j < bond.AtomCount; j++) { ac.addAtom(bond.getAtomAt(j)); } ac.addBond(bond); } } } return ac; }
/// <summary> Provide a reference to a RingSet that holds ALL rings of the molecule.<BR> /// During creation of a SMILES the aromaticity of the molecule has to be detected. /// This, in turn, requires the dermination of all rings of the molecule. If this /// computationally expensive calculation has been done beforehand, a RingSet can /// be handed over to the SmilesGenerator to save the effort of another all-rings- /// calculation. /// /// </summary> /// <param name="rings"> RingSet that holds ALL rings of the molecule /// </param> /// <returns> reference to the SmilesGenerator object this method was called for /// </returns> public virtual SmilesGenerator setRings(IRingSet rings) { this.rings = rings; return this; }
/// <summary> Checks the pathes if a ring has been found /// /// </summary> /// <param name="pathes"> The pathes to check for rings /// </param> /// <param name="ringSet"> The ringset to add the detected rings to /// </param> /// <param name="ac"> The AtomContainer with the original structure /// </param> private void detectRings(System.Collections.ArrayList pathes, IRingSet ringSet, IAtomContainer ac) { Path path = null; IRing ring = null; IBond bond = null; for (int f = 0; f < pathes.Count; f++) { path = (Path)pathes[f]; if (path.Count > 3 && path[path.Count - 1] == path[0]) { if (debug) { System.Console.Out.WriteLine("Removing path " + path.toString(originalAc) + " which is a ring."); } path.RemoveAt(0); ring = ac.Builder.newRing(); for (int g = 0; g < path.Count; g++) { ring.addAtom((IAtom)path[g]); } IBond[] bonds = ac.Bonds; for (int g = 0; g < bonds.Length; g++) { bond = bonds[g]; if (ring.contains(bond.getAtomAt(0)) && ring.contains(bond.getAtomAt(1))) { ring.addBond(bond); } } ringSet.addAtomContainer(ring); } } }
/** * Post process a fragment. --> find neutral possible neutral losses read in * from the file * * @param original * the original * * @return the i atom container set * * @throws CDKException * the CDK exception * @throws CloneNotSupportedException * the clone not supported exception */ public List<IAtomContainer> PostProcess(IAtomContainer original, double neutralLossMass) { // Render.Draw(original, "Original Main"); var ret = new List<IAtomContainer>(); allRings = new RingSet(); if (allRingsOrig.getAtomContainerCount() > 0) { // get the rings which are not broken up yet var bondMap = new Dictionary<IBond, int>(); var count = 0; foreach (var bondOrig in original.bonds().ToWindowsEnumerable<IBond>()) { bondMap[bondOrig] = count; count++; } // check for rings which are not broken up! IRingSet validRings = new RingSet(); for (var i = 0; i < allRingsOrig.getAtomContainerCount(); i++) { var bondcount = 0; foreach (var bondRing in allRingsOrig.getAtomContainer(i).bonds().ToWindowsEnumerable<IBond>()) { if (bondMap.ContainsKey(bondRing)) { bondcount++; } } if (bondcount == allRingsOrig.getAtomContainer(i).getBondCount()) { validRings.addAtomContainer(allRingsOrig.getAtomContainer(i)); } } // rings which are not split up allRings = validRings; } IAtomContainer temp = new AtomContainer(); var doneAtoms = new List<IAtom>(); var doneBonds = new List<IBond>(); // now find out the important atoms of the neutral loss var atomToStart = neutralLoss[neutralLossMass].AtomToStart; foreach (var bond in original.bonds().ToWindowsEnumerable<IBond>()) { if (doneBonds.Contains(bond)) { continue; } else { doneBonds.Add(bond); } // check if this was checked b4 foreach (var atom in bond.atoms().ToWindowsEnumerable<IAtom>()) { if (doneAtoms.Contains(atom)) { continue; } else { doneAtoms.Add(atom); } // a possible hit if (atom.getSymbol().Equals(atomToStart) && !allRings.contains(atom)) { // Render.Draw(original, "BEFORE"); // check if it is a terminal bond...and not in between! var atomList = original.getConnectedAtomsList(atom); var atomCount = 0; foreach (var iAtom in atomList.ToWindowsEnumerable<IAtom>()) { // dont check if (iAtom.getSymbol().Equals("H")) { continue; } else { atomCount++; } } // not a terminal atom...so skip it! if (atomCount > 1) { continue; } temp = checkForCompleteNeutralLoss(original, atom, neutralLossMass); if (temp.getAtomCount() > 0) { if (ConnectivityChecker.isConnected(temp)) { ret.Add(temp); } else { var set = ConnectivityChecker .partitionIntoMolecules(temp); foreach (var molecule in set.molecules().ToWindowsEnumerable<IMolecule>()) { ret.Add(molecule); } } // create a atom container temp = new AtomContainer(); } } } } return ret; }
/// <summary> Returns the geometric center of all the rings in this ringset. /// See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets /// /// </summary> /// <param name="ringSet"> Description of the Parameter /// </param> /// <returns> the geometric center of the rings in this ringset /// </returns> public static Point2d get2DCenter(IRingSet ringSet) { double centerX = 0; double centerY = 0; for (int i = 0; i < ringSet.AtomContainerCount; i++) { Point2d centerPoint = GeometryTools.get2DCenter((IRing)ringSet.getAtomContainer(i)); centerX += centerPoint.x; centerY += centerPoint.y; } Point2d point = new Point2d(centerX / ((double)ringSet.AtomContainerCount), centerY / ((double)ringSet.AtomContainerCount)); return point; }
private IRing combineRings(IRingSet ringset, int i, int j) { int c = 0; for (int b = 0; b < cb[i].Length; b++) { c = cb[i][b] + cb[j][b]; if (c > 1) break; //at least one common bond } if (c < 2) return null; IRing ring = molecule.Builder.newRing(); IRing ring1 = (IRing)ringset.getAtomContainer(i); IRing ring2 = (IRing)ringset.getAtomContainer(j); for (int b = 0; b < cb[i].Length; b++) { c = cb[i][b] + cb[j][b]; if ((c == 1) && (cb[i][b] == 1)) ring.addBond(molecule.getBondAt(b)); else if ((c == 1) && (cb[j][b] == 1)) ring.addBond(molecule.getBondAt(b)); } for (int a = 0; a < ring1.AtomCount; a++) ring.addAtom(ring1.getAtomAt(a)); for (int a = 0; a < ring2.AtomCount; a++) ring.addAtom(ring2.getAtomAt(a)); return ring; }