public override void TestToString() { IChemObject obj = NewChemObject(); IRing r = obj.Builder.NewRing(5, "C"); string description = r.ToString(); for (int i = 0; i < description.Length; i++) { Assert.IsTrue(description[i] != '\n'); Assert.IsTrue(description[i] != '\r'); } }
/// <summary> Returns the String representation of this RingSet. /// /// </summary> /// <returns> The String representation of this RingSet /// </returns> public override System.String ToString() { System.Text.StringBuilder buffer = new System.Text.StringBuilder(32); buffer.Append("RingSet("); buffer.Append(this.GetHashCode()); buffer.Append(", R=").Append(AtomContainerCount).Append(", "); IAtomContainer[] rings = AtomContainers; for (int i = 0; i < rings.Length; i++) { IRing possibleRing = (IRing)rings[i]; //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" buffer.Append(possibleRing.ToString()); if (i++ < rings.Length) { buffer.Append(", "); } } buffer.Append(')'); return(buffer.ToString()); }
/// <summary> /// Layout all rings in the given RingSet that are connected to a given Ring /// </summary> /// <param name="rs">The RingSet to be searched for rings connected to Ring</param> /// <param name="ring">The Ring for which all connected rings in RingSet are to be layed out.</param> public void PlaceConnectedRings(IRingSet rs, IRing ring, int handleType, double bondLength) { var connectedRings = rs.GetConnectedRings(ring); // Debug.WriteLine(rs.ReportRingList(Molecule)); foreach (var container in connectedRings) { IRing connectedRing = (IRing)container; if (!connectedRing.IsPlaced) { // Debug.WriteLine(ring.ToString(Molecule)); // Debug.WriteLine(connectedRing.ToString(Molecule)); IAtomContainer sharedAtoms = AtomContainerManipulator.GetIntersection(ring, connectedRing); int numSharedAtoms = sharedAtoms.Atoms.Count; Debug.WriteLine("placeConnectedRings-> connectedRing: " + (ring.ToString())); if ((numSharedAtoms == 2 && handleType == Fused) || (numSharedAtoms == 1 && handleType == Spiro) || (numSharedAtoms > 2 && handleType == Bridged)) { Vector2 sharedAtomsCenter = GeometryUtil.Get2DCenter(sharedAtoms); Vector2 oldRingCenter = GeometryUtil.Get2DCenter(ring); Vector2 tempVector = sharedAtomsCenter; Vector2 newRingCenterVector = tempVector; newRingCenterVector -= oldRingCenter; // zero (or v. small ring center) if (Math.Abs(newRingCenterVector.X) < 0.001 && Math.Abs(newRingCenterVector.Y) < 0.001) { // first see if we can use terminal bonds IAtomContainer terminalOnly = Molecule.Builder.NewAtomContainer(); foreach (IAtom atom in ring.Atoms) { if (ring.GetConnectedBonds(atom).Count() == 1) { terminalOnly.Atoms.Add(atom); } } if (terminalOnly.Atoms.Count == 2) { newRingCenterVector = GeometryUtil.Get2DCenter(terminalOnly); newRingCenterVector = oldRingCenter; connectedRing.SetProperty(RingPlacer.SnapHint, true); } else { // project coordinates on 12 axis (30 degree snaps) and choose one with most spread Vector2 vec = new Vector2(0, 1); double bestLen = -double.MaxValue; for (int i = 0; i < 12; i++) { Vector2 orth = new Vector2(-vec.Y, vec.X); orth = Vector2.Normalize(orth); double min = double.MaxValue, max = -double.MaxValue; foreach (IAtom atom in sharedAtoms.Atoms) { // s: scalar projection double s = Vector2.Dot(orth, atom.Point2D.Value); if (s < min) { min = s; } if (s > max) { max = s; } } double len = max - min; if (len > bestLen) { bestLen = len; newRingCenterVector = vec; } Rotate(vec, RAD_30); } } } Vector2 oldRingCenterVector = newRingCenterVector; Debug.WriteLine($"placeConnectedRing -> tempVector: {tempVector}, tempVector.Length: {tempVector.Length()}"); Debug.WriteLine($"placeConnectedRing -> bondCenter: {sharedAtomsCenter}"); Debug.WriteLine($"placeConnectedRing -> oldRingCenterVector.Length: {oldRingCenterVector.Length()}"); Debug.WriteLine($"placeConnectedRing -> newRingCenterVector.Length: {newRingCenterVector.Length()}"); Vector2 tempPoint = sharedAtomsCenter; tempPoint += newRingCenterVector; PlaceRing(connectedRing, sharedAtoms, sharedAtomsCenter, newRingCenterVector, bondLength); connectedRing.IsPlaced = true; PlaceConnectedRings(rs, connectedRing, handleType, bondLength); } } } }