// compare to another molecule instance; null is equivalent to empty; return values: // -1 if Mol < Other // 0 if Mol == Other // 1 if Mol > Other // can be used to sort molecules, albeit crudely; does not do any kind of canonical preprocessing public virtual int CompareTo(Molecule Other) { if (Other == null) return NumAtoms() == 0?0:1; // null is equivalent to empty if (NumAtoms() < Other.NumAtoms()) return - 1; if (NumAtoms() > Other.NumAtoms()) return 1; if (NumBonds() < Other.NumBonds()) return - 1; if (NumBonds() > Other.NumBonds()) return 1; for (int n = 1; n <= NumAtoms(); n++) { int c = String.CompareOrdinal(AtomElement(n), Other.AtomElement(n)); if (c != 0) return c; if (AtomX(n) < Other.AtomX(n)) return - 1; if (AtomX(n) > Other.AtomX(n)) return 1; if (AtomY(n) < Other.AtomY(n)) return - 1; if (AtomY(n) > Other.AtomY(n)) return 1; if (AtomCharge(n) < Other.AtomCharge(n)) return - 1; if (AtomCharge(n) > Other.AtomCharge(n)) return 1; if (AtomUnpaired(n) < Other.AtomUnpaired(n)) return - 1; if (AtomUnpaired(n) > Other.AtomUnpaired(n)) return 1; if (AtomHExplicit(n) < Other.AtomHExplicit(n)) return - 1; if (AtomHExplicit(n) > Other.AtomHExplicit(n)) return 1; } for (int n = 1; n <= NumBonds(); n++) { if (BondFrom(n) < Other.BondFrom(n)) return - 1; if (BondFrom(n) > Other.BondFrom(n)) return 1; if (BondTo(n) < Other.BondTo(n)) return - 1; if (BondTo(n) > Other.BondTo(n)) return 1; if (BondOrder(n) < Other.BondOrder(n)) return - 1; if (BondOrder(n) > Other.BondOrder(n)) return 1; if (BondType(n) < Other.BondType(n)) return - 1; if (BondType(n) > Other.BondType(n)) return 1; } return 0; }
public static void WriteMDLMOL(System.IO.StreamWriter output, Molecule mol) { //UPGRADE_ISSUE: Class 'java.text.DecimalFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextDecimalFormat'" //UPGRADE_ISSUE: Constructor 'java.text.DecimalFormat.DecimalFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextDecimalFormat'" // DecimalFormat fmt = new DecimalFormat("0.0000"); string fmtStr = "N4"; output.Write("\nNuGenChem MOLfile\n\n"); output.Write(intrpad(mol.NumAtoms(), 3) + intrpad(mol.NumBonds(), 3) + " 0 0 0 0 0 0 0 0999 V2000\n"); System.String line; for (int n = 1; n <= mol.NumAtoms(); n++) { string str = mol.AtomX(n).ToString(fmtStr); line = rep(" ", 10 - str.Length) + str; str = mol.AtomY(n).ToString(fmtStr); line += (rep(" ", 10 - str.Length) + str); line += " 0.0000 "; str = mol.AtomElement(n); line += (str + rep(" ", 4 - str.Length) + "0"); int chg = mol.AtomCharge(n), spin = mol.AtomUnpaired(n); if (chg >= - 3 && chg <= - 1) chg = 4 - chg; else if (chg == 0 && spin == 2) chg = 4; else if (chg < 1 || chg > 3) chg = 0; line += (intrpad(chg, 3) + " 0 0 0 0 0 0 0 0 0 0"); output.Write(line + "\n"); } for (int n = 1; n <= mol.NumBonds(); n++) { int type = mol.BondOrder(n); if (type < 1 || type > 3) type = 1; int stereo = mol.BondType(n); if (stereo == Molecule.BONDTYPE_NORMAL) { } else if (stereo == Molecule.BONDTYPE_INCLINED) { stereo = 1; type = 1; } else if (stereo == Molecule.BONDTYPE_DECLINED) { stereo = 6; type = 1; } else if (stereo == Molecule.BONDTYPE_UNKNOWN) { stereo = 4; type = 1; } else stereo = 0; output.Write(intrpad(mol.BondFrom(n), 3) + intrpad(mol.BondTo(n), 3) + intrpad(type, 3) + intrpad(stereo, 3) + " 0 0 0\n"); } int count = 0; line = ""; for (int n = 1; n <= mol.NumAtoms(); n++) if (mol.AtomCharge(n) != 0) { line += (intrpad(n, 4) + intrpad(mol.AtomCharge(n), 4)); count++; if (count == 8) { output.Write("M CHG" + intrpad(count, 3) + line + "\n"); count = 0; line = ""; } } if (count > 0) output.Write("M CHG" + intrpad(count, 3) + line + "\n"); count = 0; line = ""; for (int n = 1; n <= mol.NumAtoms(); n++) if (mol.AtomUnpaired(n) != 0) { line += (intrpad(n, 4) + intrpad(mol.AtomUnpaired(n), 4)); count++; if (count == 8) { output.Write("M RAD" + intrpad(count, 3) + line + "\n"); count = 0; line = ""; } } if (count > 0) output.Write("M RAD" + intrpad(count, 3) + line + "\n"); output.Write("M END\n"); output.Flush(); }
public static void WriteCMLXML(System.IO.StreamWriter output, Molecule mol) { output.Write("<cml>\n"); output.Write(" <molecule xmlns=\"http://www.xml-cml.org/schema/cml2/core\">\n"); output.Write(" <atomArray>\n"); for (int n = 1; n <= mol.NumAtoms(); n++) { output.Write(" <atom id=\"a" + n + "\" elementType=\"" + mol.AtomElement(n) + "\"" + " x2=\"" + mol.AtomX(n) + "\" y2=\"" + mol.AtomY(n) + "\" hydrogenCount=\"" + mol.AtomHydrogens(n) + "\"/>\n"); } output.Write(" </atomArray>\n"); output.Write(" <bondArray>\n"); for (int n = 1; n <= mol.NumBonds(); n++) { output.Write(" <bond id=\"b" + n + "\" atomRefs2=\"a" + mol.BondFrom(n) + " a" + mol.BondTo(n) + "\" order=\"" + mol.BondOrder(n) + "\"/>\n"); } output.Write(" </bondArray>\n"); output.Write(" </molecule>\n"); output.Write("</cml>\n"); output.Flush(); }
public static void WriteNative(System.IO.StreamWriter output, Molecule mol) { //UPGRADE_ISSUE: Class 'java.text.DecimalFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextDecimalFormat'" //UPGRADE_ISSUE: Constructor 'java.text.DecimalFormat.DecimalFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextDecimalFormat'" // DecimalFormat fmt = new DecimalFormat("0.0000"); string fmtStr = "N4"; output.Write("SketchEl!(" + mol.NumAtoms() + "," + mol.NumBonds() + ")\n"); for (int n = 1; n <= mol.NumAtoms(); n++) { System.String hy = mol.AtomHExplicit(n) != Molecule.HEXPLICIT_UNKNOWN?("e" + mol.AtomHExplicit(n)):("i" + mol.AtomHydrogens(n)); output.Write(mol.AtomElement(n) + "=" + mol.AtomX(n).ToString(fmtStr) + "," + mol.AtomY(n).ToString(fmtStr) + ";" + mol.AtomCharge(n) + "," + mol.AtomUnpaired(n) + "," + hy + "\n"); } for (int n = 1; n <= mol.NumBonds(); n++) { output.Write(mol.BondFrom(n) + "-" + mol.BondTo(n) + "=" + mol.BondOrder(n) + "," + mol.BondType(n) + "\n"); } output.Write("!End\n"); output.Flush(); }