/// <summary> Writes a SetOfMolecules to an OutputStream for the reaction. /// /// </summary> /// <param name="som"> The SetOfMolecules that is written to an OutputStream /// </param> private void writeSetOfMolecules(ISetOfMolecules som) { for (int i = 0; i < som.MoleculeCount; i++) { IMolecule mol = som.getMolecule(i); for (int j = 0; j < som.getMultiplier(i); j++) { //MemoryStream ms = new MemoryStream(); //StreamWriter sw = new StreamWriter(ms); writer.Write("$MOL\n"); MDLWriter mdlwriter = null; try { mdlwriter = new MDLWriter(writer); } catch (System.Exception ex) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //logger.error(ex.Message); //logger.debug(ex); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new CDKException("Exception while creating MDLWriter: " + ex.Message, ex); } mdlwriter.write(mol); //writer.Write(sw.ToString()); } } }
/// <summary> Reads partial atomic charges and add the to the given ChemModel. /// /// </summary> /// <param name="model">Description of the Parameter /// </param> /// <throws> CDKException Description of the Exception </throws> /// <throws> IOException Description of the Exception </throws> private void readPartialCharges(IChemModel model) { //logger.info("Reading partial atomic charges"); ISetOfMolecules moleculeSet = model.SetOfMolecules; IMolecule molecule = moleculeSet.getMolecule(0); System.String line = input.ReadLine(); // skip first line after "Total atomic charges" while (input.Peek() != -1) { line = input.ReadLine(); //logger.debug("Read charge block line: " + line); if ((line == null) || (line.IndexOf("Sum of Mulliken charges") >= 0)) { //logger.debug("End of charge block found"); break; } System.IO.StringReader sr = new System.IO.StringReader(line); SupportClass.StreamTokenizerSupport tokenizer = new SupportClass.StreamTokenizerSupport(sr); if (tokenizer.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER) { //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'" int atomCounter = (int)tokenizer.nval; tokenizer.NextToken(); // ignore the symbol double charge; if (tokenizer.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER) { charge = tokenizer.nval; //logger.debug("Found charge for atom " + atomCounter + ": " + charge); } else { throw new CDKException("Error while reading charge: expected double."); } IAtom atom = molecule.getAtomAt(atomCounter - 1); atom.setCharge(charge); } } }
/// <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 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; } } }