/// <summary> Writes a Molecule to an OutputStream in MDL sdf format. /// /// </summary> /// <param name="container"> Molecule that is written to an OutputStream /// </param> /// <param name="isVisible">Should a certain atom be written to mdl? /// </param> public virtual void writeMolecule(IMolecule container, bool[] isVisible) { System.String line = ""; // taking care of the $$$$ signs: // we do not write such a sign at the end of the first molecule, thus we have to write on BEFORE the second molecule if (moleculeNumber == 2) { writer.Write("$$$$"); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } // write header block // lines get shortened to 80 chars, that's in the spec System.String title = (System.String)container.getProperty(CDKConstants.TITLE); if (title == null) { title = ""; } if (title.Length > 80) { title = title.Substring(0, (80) - (0)); } writer.Write(title + "\n"); /* From CTX spec * This line has the format: * IIPPPPPPPPMMDDYYHHmmddSSssssssssssEEEEEEEEEEEERRRRRR * (FORTRAN: A2<--A8--><---A10-->A2I2<--F10.5-><---F12.5--><-I6-> ) * User's first and last initials (l), program name (P), * date/time (M/D/Y,H:m), dimensional codes (d), scaling factors (S, s), * energy (E) if modeling program input, internal registry number (R) * if input through MDL form. * A blank line can be substituted for line 2. */ writer.Write(" CDK "); //UPGRADE_ISSUE: Constructor 'java.text.SimpleDateFormat.SimpleDateFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextSimpleDateFormat'" //UPGRADE_TODO: The equivalent in .NET for method 'java.util.Calendar.getTime' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" System.TimeZone generatedAux3 = System.TimeZone.CurrentTimeZone; //writer.Write(SupportClass.FormatDateTime(new SimpleDateFormat("M/d/y,H:m", new System.Globalization.CultureInfo("en-US")), SupportClass.CalendarManager.manager.GetDateTime(new System.Globalization.GregorianCalendar()))); writer.Write('\n'); System.String comment = (System.String)container.getProperty(CDKConstants.REMARK); if (comment == null) { comment = ""; } if (comment.Length > 80) { comment = comment.Substring(0, (80) - (0)); } writer.Write(comment + "\n"); // write Counts line int upToWhichAtom = 0; for (int i = 0; i < isVisible.Length; i++) { if (isVisible[i]) { upToWhichAtom++; } } line += formatMDLInt(upToWhichAtom, 3); int numberOfBonds = 0; if (upToWhichAtom < container.AtomCount) { for (int i = 0; i < container.getBondCount(); i++) { if (isVisible[container.getAtomNumber(container.getBondAt(i).getAtoms()[0])] && isVisible[container.getAtomNumber(container.getBondAt(i).getAtoms()[1])]) { numberOfBonds++; } } } else { numberOfBonds = container.getBondCount(); } line += formatMDLInt(numberOfBonds, 3); line += " 0 0 0 0 0 0 0 0999 V2000\n"; writer.Write(line); // write Atom block IAtom[] atoms = container.Atoms; for (int f = 0; f < atoms.Length; f++) { if (isVisible[f]) { IAtom atom = atoms[f]; line = ""; if (atom.getPoint3d() != null) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLFloat((float)atom.X3d); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLFloat((float)atom.Y3d); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += (formatMDLFloat((float)atom.Z3d) + " "); } else if (atom.getPoint2d() != null) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLFloat((float)atom.X2d); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLFloat((float)atom.Y2d); line += " 0.0000 "; } else { // if no coordinates available, then output a number // of zeros line += formatMDLFloat((float)0.0); line += formatMDLFloat((float)0.0); line += (formatMDLFloat((float)0.0) + " "); } if (container.getAtomAt(f) is IPseudoAtom) { line += formatMDLString(((IPseudoAtom)container.getAtomAt(f)).Label, 3); } else { line += formatMDLString(container.getAtomAt(f).Symbol, 3); } line += " 0 0 0 0 0 0 0 0 0 0 0 0"; writer.Write(line); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } // write Bond block IBond[] bonds = container.Bonds; for (int g = 0; g < bonds.Length; g++) { if (upToWhichAtom == container.AtomCount || (isVisible[container.getAtomNumber(container.getBondAt(g).getAtoms()[0])] && isVisible[container.getAtomNumber(container.getBondAt(g).getAtoms()[1])])) { IBond bond = bonds[g]; if (bond.getAtoms().Length != 2) { //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'" //logger.warn("Skipping bond with more/less than two atoms: " + bond); } else { if (bond.Stereo == CDKConstants.STEREO_BOND_UP_INV || bond.Stereo == CDKConstants.STEREO_BOND_DOWN_INV) { // turn around atom coding to correct for inv stereo line = formatMDLInt(container.getAtomNumber(bond.getAtomAt(1)) + 1, 3); line += formatMDLInt(container.getAtomNumber(bond.getAtomAt(0)) + 1, 3); } else { line = formatMDLInt(container.getAtomNumber(bond.getAtomAt(0)) + 1, 3); line += formatMDLInt(container.getAtomNumber(bond.getAtomAt(1)) + 1, 3); } //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLInt((int)bond.Order, 3); line += " "; switch (bond.Stereo) { case CDKConstants.STEREO_BOND_UP: line += "1"; break; case CDKConstants.STEREO_BOND_UP_INV: line += "1"; break; case CDKConstants.STEREO_BOND_DOWN: line += "6"; break; case CDKConstants.STEREO_BOND_DOWN_INV: line += "6"; break; default: line += "0"; break; } line += " 0 0 0 "; writer.Write(line); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } } // write formal atomic charges for (int i = 0; i < atoms.Length; i++) { IAtom atom = atoms[i]; int charge = atom.getFormalCharge(); if (charge != 0) { writer.Write("M CHG 1 "); writer.Write(formatMDLInt(i + 1, 3)); writer.Write(" "); writer.Write(formatMDLInt(charge, 3)); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } // write formal isotope information for (int i = 0; i < atoms.Length; i++) { IAtom atom = atoms[i]; if (!(atom is IPseudoAtom)) { int atomicMass = atom.MassNumber; int majorMass = IsotopeFactory.getInstance(atom.Builder).getMajorIsotope(atom.Symbol).MassNumber; if (atomicMass != 0 && atomicMass != majorMass) { writer.Write("M ISO 1 "); writer.Write(formatMDLInt(i + 1, 3)); writer.Write(" "); writer.Write(formatMDLInt(atomicMass, 3)); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } } // close molecule writer.Write("M END"); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); //write sdfields, if any if (sdFields != null) { //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'" CSGraphT.SupportClass.SetSupport set_Renamed = new CSGraphT.SupportClass.HashSetSupport(sdFields.Keys); System.Collections.IEnumerator iterator = set_Renamed.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 (iterator.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'" System.Object element = iterator.Current; writer.Write("> <" + ((System.String)element) + ">"); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); //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'" writer.Write(sdFields[element].ToString()); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } // taking care of the $$$$ signs: // we write such a sign at the end of all except the first molecule if (moleculeNumber != 1) { writer.Write("$$$$"); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } moleculeNumber++; writer.Flush(); }
/// <summary> Generate canonical SMILES from the <code>molecule</code>. This method /// canonicaly lables the molecule but does not perform any checks on the /// chemical validity of the molecule. /// 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> /// <returns> Description of the Returned Value /// </returns> /// <seealso cref="org.openscience.cdk.graph.invariant.CanonicalLabeler.canonLabel(IAtomContainer)"> /// </seealso> //UPGRADE_NOTE: Synchronized keyword was removed from method 'createSMILES'. Lock expression was added. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1027'" public virtual System.String createSMILES(IMolecule molecule) { lock (this) { try { return (createSMILES(molecule, false, new bool[molecule.getBondCount()])); } catch (CDKException exception) { // This exception can only happen if a chiral smiles is requested return (""); } } }
/// <summary> Writes a single frame in XYZ format to the Writer. /// /// </summary> /// <param name="mol">the Molecule to write /// </param> public virtual void writeMolecule(IMolecule mol) { try { /* # Name: benzene # Creating user name: tom # Creation time: Wed Dec 28 00:18:30 1988 # Modifying user name: tom # Modification time: Wed Dec 28 00:18:30 1988*/ //logger.debug("Writing header..."); if (mol.getProperty(CDKConstants.TITLE) != null) { //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'" writer.Write("# Name: " + mol.getProperty(CDKConstants.TITLE) + "\n"); } // FIXME: add other types of meta data //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); /* @<TRIPOS>MOLECULE benzene 12 12 1 0 0 SMALL NO_CHARGES */ //logger.debug("Writing molecule block..."); writer.Write("@<TRIPOS>MOLECULE\n"); writer.Write(mol.ID + "\n"); writer.Write(mol.AtomCount + " " + mol.getBondCount() + "\n"); // that's the minimum amount of info required the format writer.Write("SMALL\n"); // no biopolymer writer.Write("NO CHARGES\n"); // other options include Gasteiger charges /* @<TRIPOS>ATOM 1 C1 1.207 2.091 0.000 C.ar 1 BENZENE 0.000 2 C2 2.414 1.394 0.000 C.ar 1 BENZENE 0.000 3 C3 2.414 0.000 0.000 C.ar 1 BENZENE 0.000 4 C4 1.207 -0.697 0.000 C.ar 1 BENZENE 0.000 5 C5 0.000 0.000 0.000 C.ar 1 BENZENE 0.000 6 C6 0.000 1.394 0.000 C.ar 1 BENZENE 0.000 7 H1 1.207 3.175 0.000 H 1 BENZENE 0.000 8 H2 3.353 1.936 0.000 H 1 BENZENE 0.000 9 H3 3.353 -0.542 0.000 H 1 BENZENE 0.000 10 H4 1.207 -1.781 0.000 H 1 BENZENE 0.000 11 H5 -0.939 -0.542 0.000 H 1 BENZENE 0.000 12 H6 -0.939 1.936 0.000 H 1 BENZENE 0.000 */ // write atom block //logger.debug("Writing atom block..."); writer.Write("@<TRIPOS>ATOM\n"); IAtom[] atoms = mol.Atoms; for (int i = 0; i < atoms.Length; i++) { writer.Write(i + " " + atoms[i].ID + " "); if (atoms[i].getPoint3d() != null) { writer.Write(atoms[i].X3d + " "); writer.Write(atoms[i].Y3d + " "); writer.Write(atoms[i].Z3d + " "); } else if (atoms[i].getPoint2d() != null) { writer.Write(atoms[i].X2d + " "); writer.Write(atoms[i].Y2d + " "); writer.Write(" 0.000 "); } else { writer.Write("0.000 0.000 0.000 "); } writer.Write(atoms[i].Symbol + "\n"); // FIXME: should use perceived Mol2 Atom Types! } /* @<TRIPOS>BOND 1 1 2 ar 2 1 6 ar 3 2 3 ar 4 3 4 ar 5 4 5 ar 6 5 6 ar 7 1 7 1 8 2 8 1 9 3 9 1 10 4 10 1 11 5 11 1 12 6 12 1*/ // write bond block //logger.debug("Writing bond block..."); writer.Write("@<TRIPOS>BOND\n"); IBond[] bonds = mol.Bonds; for (int i = 0; i < bonds.Length; i++) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" writer.Write(i + " " + mol.getAtomNumber(bonds[i].getAtomAt(0)) + " " + mol.getAtomNumber(bonds[i].getAtomAt(1)) + " " + ((int)bonds[i].Order) + "\n"); } } catch (System.IO.IOException e) { throw e; } }
/// <summary> Writes a single frame in XYZ format to the Writer. /// /// </summary> /// <param name="mol">the Molecule to write /// </param> public virtual void writeMolecule(IMolecule mol) { try { /* # Name: benzene # Creating user name: tom # Creation time: Wed Dec 28 00:18:30 1988 # # Modifying user name: tom # Modification time: Wed Dec 28 00:18:30 1988*/ //logger.debug("Writing header..."); if (mol.getProperty(CDKConstants.TITLE) != null) { //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'" writer.Write("# Name: " + mol.getProperty(CDKConstants.TITLE) + "\n"); } // FIXME: add other types of meta data //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); /* * @<TRIPOS>MOLECULE * benzene * 12 12 1 0 0 * SMALL * NO_CHARGES */ //logger.debug("Writing molecule block..."); writer.Write("@<TRIPOS>MOLECULE\n"); writer.Write(mol.ID + "\n"); writer.Write(mol.AtomCount + " " + mol.getBondCount() + "\n"); // that's the minimum amount of info required the format writer.Write("SMALL\n"); // no biopolymer writer.Write("NO CHARGES\n"); // other options include Gasteiger charges /* * @<TRIPOS>ATOM * 1 C1 1.207 2.091 0.000 C.ar 1 BENZENE 0.000 * 2 C2 2.414 1.394 0.000 C.ar 1 BENZENE 0.000 * 3 C3 2.414 0.000 0.000 C.ar 1 BENZENE 0.000 * 4 C4 1.207 -0.697 0.000 C.ar 1 BENZENE 0.000 * 5 C5 0.000 0.000 0.000 C.ar 1 BENZENE 0.000 * 6 C6 0.000 1.394 0.000 C.ar 1 BENZENE 0.000 * 7 H1 1.207 3.175 0.000 H 1 BENZENE 0.000 * 8 H2 3.353 1.936 0.000 H 1 BENZENE 0.000 * 9 H3 3.353 -0.542 0.000 H 1 BENZENE 0.000 * 10 H4 1.207 -1.781 0.000 H 1 BENZENE 0.000 * 11 H5 -0.939 -0.542 0.000 H 1 BENZENE 0.000 * 12 H6 -0.939 1.936 0.000 H 1 BENZENE 0.000 */ // write atom block //logger.debug("Writing atom block..."); writer.Write("@<TRIPOS>ATOM\n"); IAtom[] atoms = mol.Atoms; for (int i = 0; i < atoms.Length; i++) { writer.Write(i + " " + atoms[i].ID + " "); if (atoms[i].getPoint3d() != null) { writer.Write(atoms[i].X3d + " "); writer.Write(atoms[i].Y3d + " "); writer.Write(atoms[i].Z3d + " "); } else if (atoms[i].getPoint2d() != null) { writer.Write(atoms[i].X2d + " "); writer.Write(atoms[i].Y2d + " "); writer.Write(" 0.000 "); } else { writer.Write("0.000 0.000 0.000 "); } writer.Write(atoms[i].Symbol + "\n"); // FIXME: should use perceived Mol2 Atom Types! } /* * @<TRIPOS>BOND * 1 1 2 ar * 2 1 6 ar * 3 2 3 ar * 4 3 4 ar * 5 4 5 ar * 6 5 6 ar * 7 1 7 1 * 8 2 8 1 * 9 3 9 1 * 10 4 10 1 * 11 5 11 1 * 12 6 12 1*/ // write bond block //logger.debug("Writing bond block..."); writer.Write("@<TRIPOS>BOND\n"); IBond[] bonds = mol.Bonds; for (int i = 0; i < bonds.Length; i++) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" writer.Write(i + " " + mol.getAtomNumber(bonds[i].getAtomAt(0)) + " " + mol.getAtomNumber(bonds[i].getAtomAt(1)) + " " + ((int)bonds[i].Order) + "\n"); } } catch (System.IO.IOException e) { throw e; } }
/// <summary> writes all the molecules supplied in a SetOfMolecules class to /// a single HIN file. You can also supply a single Molecule object /// as well /// </summary> /// <param name="mol">the Molecule to write /// </param> private void writeMolecule(ISetOfMolecules som) { //int na = 0; //String info = ""; System.String sym = ""; double chrg = 0.0; //boolean writecharge = true; for (int molnum = 0; molnum < som.MoleculeCount; molnum++) { IMolecule mol = som.getMolecule(molnum); try { int natom = mol.AtomCount; int nbond = mol.getBondCount(); System.String molname = "mol " + (molnum + 1) + " " + ((System.String)mol.getProperty(CDKConstants.TITLE)); //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'" writer.Write(molname.ToCharArray(), 0, molname.Length); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); // Loop through the atoms and write them out: IAtom[] atoms = mol.Atoms; IBond[] bonds = mol.Bonds; for (int i = 0; i < natom; i++) { System.String line = "atom "; IAtom a = atoms[i]; sym = a.Symbol; chrg = a.getCharge(); Point3d p3 = a.getPoint3d(); line = line + ((System.Int32)(i + 1)).ToString() + " - " + sym + " ** - " + ((double)chrg).ToString() + " " + p3.x.ToString() + " " + p3.y.ToString() + " " + p3.z.ToString() + " "; System.String buf = ""; int ncon = 0; for (int j = 0; j < nbond; j++) { IBond b = bonds[j]; if (b.contains(a)) { // current atom is in the bond so lets get the connected atom IAtom ca = b.getConnectedAtom(a); double bo = b.Order; int serial = -1; System.String bt = ""; // get the serial no for this atom serial = mol.getAtomNumber(ca); if (bo == 1) { bt = new System.Text.StringBuilder("s").ToString(); } else if (bo == 2) { bt = new System.Text.StringBuilder("d").ToString(); } else if (bo == 3) { bt = new System.Text.StringBuilder("t").ToString(); } else if (bo == 1.5) { bt = new System.Text.StringBuilder("a").ToString(); } buf = buf + ((System.Int32)(serial + 1)).ToString() + " " + bt + " "; ncon++; } } line = line + " " + ((System.Int32)ncon).ToString() + " " + buf; //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'" writer.Write(line.ToCharArray(), 0, line.Length); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } System.String buf2 = "endmol " + (molnum + 1); //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'" writer.Write(buf2.ToCharArray(), 0, buf2.Length); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } catch (System.IO.IOException e) { throw e; } } }
/// <summary> Writes a Molecule to an OutputStream in MDL sdf format. /// /// </summary> /// <param name="container"> Molecule that is written to an OutputStream /// </param> /// <param name="isVisible">Should a certain atom be written to mdl? /// </param> public virtual void writeMolecule(IMolecule container, bool[] isVisible) { System.String line = ""; // taking care of the $$$$ signs: // we do not write such a sign at the end of the first molecule, thus we have to write on BEFORE the second molecule if (moleculeNumber == 2) { writer.Write("$$$$"); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } // write header block // lines get shortened to 80 chars, that's in the spec System.String title = (System.String)container.getProperty(CDKConstants.TITLE); if (title == null) title = ""; if (title.Length > 80) title = title.Substring(0, (80) - (0)); writer.Write(title + "\n"); /* From CTX spec * This line has the format: * IIPPPPPPPPMMDDYYHHmmddSSssssssssssEEEEEEEEEEEERRRRRR * (FORTRAN: A2<--A8--><---A10-->A2I2<--F10.5-><---F12.5--><-I6-> ) * User's first and last initials (l), program name (P), * date/time (M/D/Y,H:m), dimensional codes (d), scaling factors (S, s), * energy (E) if modeling program input, internal registry number (R) * if input through MDL form. * A blank line can be substituted for line 2. */ writer.Write(" CDK "); //UPGRADE_ISSUE: Constructor 'java.text.SimpleDateFormat.SimpleDateFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextSimpleDateFormat'" //UPGRADE_TODO: The equivalent in .NET for method 'java.util.Calendar.getTime' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" System.TimeZone generatedAux3 = System.TimeZone.CurrentTimeZone; //writer.Write(SupportClass.FormatDateTime(new SimpleDateFormat("M/d/y,H:m", new System.Globalization.CultureInfo("en-US")), SupportClass.CalendarManager.manager.GetDateTime(new System.Globalization.GregorianCalendar()))); writer.Write('\n'); System.String comment = (System.String)container.getProperty(CDKConstants.REMARK); if (comment == null) comment = ""; if (comment.Length > 80) comment = comment.Substring(0, (80) - (0)); writer.Write(comment + "\n"); // write Counts line int upToWhichAtom = 0; for (int i = 0; i < isVisible.Length; i++) { if (isVisible[i]) upToWhichAtom++; } line += formatMDLInt(upToWhichAtom, 3); int numberOfBonds = 0; if (upToWhichAtom < container.AtomCount) { for (int i = 0; i < container.getBondCount(); i++) { if (isVisible[container.getAtomNumber(container.getBondAt(i).getAtoms()[0])] && isVisible[container.getAtomNumber(container.getBondAt(i).getAtoms()[1])]) numberOfBonds++; } } else { numberOfBonds = container.getBondCount(); } line += formatMDLInt(numberOfBonds, 3); line += " 0 0 0 0 0 0 0 0999 V2000\n"; writer.Write(line); // write Atom block IAtom[] atoms = container.Atoms; for (int f = 0; f < atoms.Length; f++) { if (isVisible[f]) { IAtom atom = atoms[f]; line = ""; if (atom.getPoint3d() != null) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLFloat((float)atom.X3d); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLFloat((float)atom.Y3d); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += (formatMDLFloat((float)atom.Z3d) + " "); } else if (atom.getPoint2d() != null) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLFloat((float)atom.X2d); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLFloat((float)atom.Y2d); line += " 0.0000 "; } else { // if no coordinates available, then output a number // of zeros line += formatMDLFloat((float)0.0); line += formatMDLFloat((float)0.0); line += (formatMDLFloat((float)0.0) + " "); } if (container.getAtomAt(f) is IPseudoAtom) line += formatMDLString(((IPseudoAtom)container.getAtomAt(f)).Label, 3); else line += formatMDLString(container.getAtomAt(f).Symbol, 3); line += " 0 0 0 0 0 0 0 0 0 0 0 0"; writer.Write(line); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } // write Bond block IBond[] bonds = container.Bonds; for (int g = 0; g < bonds.Length; g++) { if (upToWhichAtom == container.AtomCount || (isVisible[container.getAtomNumber(container.getBondAt(g).getAtoms()[0])] && isVisible[container.getAtomNumber(container.getBondAt(g).getAtoms()[1])])) { IBond bond = bonds[g]; if (bond.getAtoms().Length != 2) { //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'" //logger.warn("Skipping bond with more/less than two atoms: " + bond); } else { if (bond.Stereo == CDKConstants.STEREO_BOND_UP_INV || bond.Stereo == CDKConstants.STEREO_BOND_DOWN_INV) { // turn around atom coding to correct for inv stereo line = formatMDLInt(container.getAtomNumber(bond.getAtomAt(1)) + 1, 3); line += formatMDLInt(container.getAtomNumber(bond.getAtomAt(0)) + 1, 3); } else { line = formatMDLInt(container.getAtomNumber(bond.getAtomAt(0)) + 1, 3); line += formatMDLInt(container.getAtomNumber(bond.getAtomAt(1)) + 1, 3); } //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" line += formatMDLInt((int)bond.Order, 3); line += " "; switch (bond.Stereo) { case CDKConstants.STEREO_BOND_UP: line += "1"; break; case CDKConstants.STEREO_BOND_UP_INV: line += "1"; break; case CDKConstants.STEREO_BOND_DOWN: line += "6"; break; case CDKConstants.STEREO_BOND_DOWN_INV: line += "6"; break; default: line += "0"; break; } line += " 0 0 0 "; writer.Write(line); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } } // write formal atomic charges for (int i = 0; i < atoms.Length; i++) { IAtom atom = atoms[i]; int charge = atom.getFormalCharge(); if (charge != 0) { writer.Write("M CHG 1 "); writer.Write(formatMDLInt(i + 1, 3)); writer.Write(" "); writer.Write(formatMDLInt(charge, 3)); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } // write formal isotope information for (int i = 0; i < atoms.Length; i++) { IAtom atom = atoms[i]; if (!(atom is IPseudoAtom)) { int atomicMass = atom.MassNumber; int majorMass = IsotopeFactory.getInstance(atom.Builder).getMajorIsotope(atom.Symbol).MassNumber; if (atomicMass != 0 && atomicMass != majorMass) { writer.Write("M ISO 1 "); writer.Write(formatMDLInt(i + 1, 3)); writer.Write(" "); writer.Write(formatMDLInt(atomicMass, 3)); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } } // close molecule writer.Write("M END"); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); //write sdfields, if any if (sdFields != null) { //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'" CSGraphT.SupportClass.SetSupport set_Renamed = new CSGraphT.SupportClass.HashSetSupport(sdFields.Keys); System.Collections.IEnumerator iterator = set_Renamed.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 (iterator.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'" System.Object element = iterator.Current; writer.Write("> <" + ((System.String)element) + ">"); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); //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'" writer.Write(sdFields[element].ToString()); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } } // taking care of the $$$$ signs: // we write such a sign at the end of all except the first molecule if (moleculeNumber != 1) { writer.Write("$$$$"); //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" writer.WriteLine(); } moleculeNumber++; writer.Flush(); }