/// <summary> Reads a text based configuration file. /// /// </summary> /// <param name="builder">IChemObjectBuilder used to construct the IAtomType's. /// </param> /// <throws> IOException when a problem occured with reading from the InputStream </throws> /// <returns> A Vector with read IAtomType's. /// </returns> public virtual System.Collections.ArrayList readAtomTypes(IChemObjectBuilder builder) { System.Collections.ArrayList atomTypes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); if (ins == null) { // trying the default //System.out.println("readAtomTypes getResourceAsStream:" // + configFile); //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'" //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetClassLoader'" ins = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + configFile); } if (ins == null) throw new System.IO.IOException("There was a problem getting the default stream: " + configFile); // read the contents from file //UPGRADE_TODO: The differences in the expected value of parameters for constructor 'java.io.BufferedReader.BufferedReader' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'" System.IO.StreamReader reader = new System.IO.StreamReader(new System.IO.StreamReader(ins, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(ins, System.Text.Encoding.Default).CurrentEncoding, false, 1024); SupportClass.Tokenizer tokenizer; System.String string_Renamed; while (true) { string_Renamed = reader.ReadLine(); if (string_Renamed == null) { break; } if (!string_Renamed.StartsWith("#")) { System.String name = ""; System.String rootType = ""; int atomicNumber = 0, colorR = 0, colorG = 0, colorB = 0; double mass = 0.0, vdwaals = 0.0, covalent = 0.0; tokenizer = new SupportClass.Tokenizer(string_Renamed, "\t ,;"); int tokenCount = tokenizer.Count; if (tokenCount == 9) { name = tokenizer.NextToken(); rootType = tokenizer.NextToken(); System.String san = tokenizer.NextToken(); System.String sam = tokenizer.NextToken(); System.String svdwaals = tokenizer.NextToken(); System.String scovalent = tokenizer.NextToken(); System.String sColorR = tokenizer.NextToken(); System.String sColorG = tokenizer.NextToken(); System.String sColorB = tokenizer.NextToken(); try { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" mass = System.Double.Parse(sam); //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" vdwaals = System.Double.Parse(svdwaals); //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" covalent = System.Double.Parse(scovalent); atomicNumber = System.Int32.Parse(san); colorR = System.Int32.Parse(sColorR); colorG = System.Int32.Parse(sColorG); colorB = System.Int32.Parse(sColorB); } catch (System.FormatException nfe) { throw new System.IO.IOException("AtomTypeTable.ReadAtypes: " + "Malformed Number"); } IAtomType atomType = builder.newAtomType(name, rootType); atomType.AtomicNumber = atomicNumber; atomType.setExactMass(mass); atomType.VanderwaalsRadius = vdwaals; atomType.CovalentRadius = covalent; System.Drawing.Color color = System.Drawing.Color.FromArgb(colorR, colorG, colorB); atomType.setProperty("org.openscience.cdk.renderer.color", color); atomTypes.Add(atomType); } else { throw new System.IO.IOException("AtomTypeTable.ReadAtypes: " + "Wrong Number of fields"); } } } // end while ins.Close(); return atomTypes; }
/// <summary> Creates a String of the Class name of the <code>IChemObject</code> reader /// for this file format. The input is read line-by-line /// until a line containing an identifying string is /// found. /// /// <p>The ReaderFactory detects more formats than the CDK /// has Readers for. /// /// <p>This method is not able to detect the format of gziped files. /// Use <code>guessFormat(InputStream)</code> instead for such files. /// /// </summary> /// <throws> IOException if an I/O error occurs </throws> /// <throws> IllegalArgumentException if the input is null </throws> /// <summary> /// </summary> /// <seealso cref="guessFormat(InputStream)"> /// </seealso> public virtual IChemFormat guessFormat(StreamReader input) { if (input == null) { throw new System.ArgumentException("input cannot be null"); } // make a copy of the header char[] header = new char[this.headerLength]; //UPGRADE_ISSUE: Method 'java.io.BufferedReader.markSupported' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000'" //if (!input.markSupported()) //{ // //logger.error("Mark not supported"); // throw new System.ArgumentException("input must support mark"); //} //int pos = this.headerLength;//input.mark(this.headerLength); input.Read(header, 0, this.headerLength); input.BaseStream.Seek(0, SeekOrigin.Begin); //UPGRADE_ISSUE: Constructor 'java.io.BufferedReader.BufferedReader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReaderBufferedReader_javaioReader'" System.IO.StringReader buffer = new StringReader(new System.String(header)); /* Search file for a line containing an identifying keyword */ System.String line = null; int lineNumber = 1; while ((line = buffer.ReadLine()) != null) { //logger.debug(lineNumber + ": ", line); for (int i = 0; i < formats.Count; i++) { IChemFormatMatcher cfMatcher = (IChemFormatMatcher)formats[i]; if (cfMatcher.matches(lineNumber, line)) { //logger.info("Detected format: ", cfMatcher.FormatName); return cfMatcher; } } lineNumber++; } //logger.warn("Now comes the tricky and more difficult ones...."); //UPGRADE_ISSUE: Constructor 'java.io.BufferedReader.BufferedReader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReaderBufferedReader_javaioReader'" buffer = new StringReader(new System.String(header)); line = buffer.ReadLine(); // is it a XYZ file? SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line.Trim()); try { int tokenCount = tokenizer.Count; if (tokenCount == 1) { System.Int32.Parse(tokenizer.NextToken()); // if not failed, then it is a XYZ file return null;// new org.openscience.cdk.io.formats.XYZFormat(); } else if (tokenCount == 2) { System.Int32.Parse(tokenizer.NextToken()); if ("Bohr".ToUpper().Equals(tokenizer.NextToken().ToUpper())) { return null;// new org.openscience.cdk.io.formats.XYZFormat(); } } } catch (System.FormatException exception) { //logger.info("No, it's not a XYZ file"); } //logger.warn("File format undetermined"); return null; }
/// <summary> Private method that actually parses the input to read a ChemFile /// object. /// /// </summary> /// <returns> A ChemFile containing the data parsed from input. /// </returns> private IChemFile readChemFile(IChemFile file) { IChemSequence chemSequence = file.Builder.newChemSequence(); int number_of_atoms = 0; SupportClass.Tokenizer tokenizer; try { System.String line = input.ReadLine(); while (line.StartsWith("#")) line = input.ReadLine(); /*while (input.ready() && line != null) {*/ // System.out.println("lauf"); // parse frame by frame tokenizer = new SupportClass.Tokenizer(line, "\t ,;"); System.String token = tokenizer.NextToken(); number_of_atoms = System.Int32.Parse(token); System.String info = input.ReadLine(); IChemModel chemModel = file.Builder.newChemModel(); ISetOfMolecules setOfMolecules = file.Builder.newSetOfMolecules(); IMolecule m = file.Builder.newMolecule(); m.setProperty(CDKConstants.TITLE, info); System.String[] types = new System.String[number_of_atoms]; double[] d = new double[number_of_atoms]; int[] d_atom = new int[number_of_atoms]; // Distances double[] a = new double[number_of_atoms]; int[] a_atom = new int[number_of_atoms]; // Angles double[] da = new double[number_of_atoms]; int[] da_atom = new int[number_of_atoms]; // Diederangles //Point3d[] pos = new Point3d[number_of_atoms]; // calculated positions int i = 0; while (i < number_of_atoms) { line = input.ReadLine(); // System.out.println("line:\""+line+"\""); if (line == null) break; if (line.StartsWith("#")) { // skip comment in file } else { d[i] = 0d; d_atom[i] = -1; a[i] = 0d; a_atom[i] = -1; da[i] = 0d; da_atom[i] = -1; tokenizer = new SupportClass.Tokenizer(line, "\t ,;"); int fields = tokenizer.Count; if (fields < System.Math.Min(i * 2 + 1, 7)) { // this is an error but cannot throw exception } else if (i == 0) { types[i] = tokenizer.NextToken(); i++; } else if (i == 1) { types[i] = tokenizer.NextToken(); d_atom[i] = (System.Int32.Parse(tokenizer.NextToken())) - 1; //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" d[i] = (System.Double.Parse(tokenizer.NextToken())); i++; } else if (i == 2) { types[i] = tokenizer.NextToken(); d_atom[i] = (System.Int32.Parse(tokenizer.NextToken())) - 1; //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" d[i] = (System.Double.Parse(tokenizer.NextToken())); a_atom[i] = (System.Int32.Parse(tokenizer.NextToken())) - 1; //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" a[i] = (System.Double.Parse(tokenizer.NextToken())); i++; } else { types[i] = tokenizer.NextToken(); d_atom[i] = (System.Int32.Parse(tokenizer.NextToken())) - 1; //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" d[i] = (System.Double.Parse(tokenizer.NextToken())); a_atom[i] = (System.Int32.Parse(tokenizer.NextToken())) - 1; //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" a[i] = (System.Double.Parse(tokenizer.NextToken())); da_atom[i] = (System.Int32.Parse(tokenizer.NextToken())) - 1; //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" da[i] = (System.Double.Parse(tokenizer.NextToken())); i++; } } } // calculate cartesian coordinates Point3d[] cartCoords = ZMatrixTools.zmatrixToCartesian(d, d_atom, a, a_atom, da, da_atom); for (i = 0; i < number_of_atoms; i++) { m.addAtom(file.Builder.newAtom(types[i], cartCoords[i])); } // System.out.println("molecule:\n"+m); setOfMolecules.addMolecule(m); chemModel.SetOfMolecules = setOfMolecules; chemSequence.addChemModel(chemModel); line = input.ReadLine(); file.addChemSequence(chemSequence); } catch (System.IO.IOException e) { // should make some noise now file = null; } return file; }
/// <summary> Reads labels.</summary> public virtual void readSGroup(IAtomContainer readData) { bool foundEND = false; while (Ready && !foundEND) { System.String command = readCommand(); if ("END SGROUP".Equals(command)) { foundEND = true; } else { //logger.debug("Parsing Sgroup line: " + command); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(command); // parse the index System.String indexString = tokenizer.NextToken(); //logger.warn("Skipping external index: " + indexString); // parse command type System.String type = tokenizer.NextToken(); // parse the external index System.String externalIndexString = tokenizer.NextToken(); //logger.warn("Skipping external index: " + externalIndexString); // the rest are key=value fields System.Collections.Hashtable options = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); if (command.IndexOf("=") != -1) { options = parseOptions(exhaustStringTokenizer(tokenizer)); } // now interpret line if (type.StartsWith("SUP")) { System.Collections.IEnumerator keys = options.Keys.GetEnumerator(); int atomID = -1; System.String label = ""; //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' 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_javautilEnumerationhasMoreElements'" while (keys.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' 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_javautilEnumerationnextElement'" System.String key = (System.String)keys.Current; System.String value_Renamed = (System.String)options[key]; try { if (key.Equals("ATOMS")) { SupportClass.Tokenizer atomsTokenizer = new SupportClass.Tokenizer(value_Renamed); System.Int32.Parse(atomsTokenizer.NextToken()); // should be 1, int atomCount = atomID = System.Int32.Parse(atomsTokenizer.NextToken()); } else if (key.Equals("LABEL")) { label = value_Renamed; } else { //logger.warn("Not parsing key: " + key); } } catch (System.Exception exception) { //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'" System.String error = "Error while parsing key/value " + key + "=" + value_Renamed + ": " + exception.Message; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } if (atomID != -1 && label.Length > 0) { IAtom atom = readData.getAtomAt(atomID - 1); if (!(atom is IPseudoAtom)) { atom = readData.Builder.newPseudoAtom(atom); } ((IPseudoAtom)atom).Label = label; readData.setAtomAt(atomID - 1, atom); } } } else { //logger.warn("Skipping unrecognized SGROUP type: " + type); } } } }
private IChemModel readChemModel(IChemModel model) { int[] atoms = new int[1]; double[] atomxs = new double[1]; double[] atomys = new double[1]; double[] atomzs = new double[1]; double[] atomcharges = new double[1]; int[] bondatomid1 = new int[1]; int[] bondatomid2 = new int[1]; int[] bondorder = new int[1]; int numberOfAtoms = 0; int numberOfBonds = 0; try { System.String line = input.ReadLine(); while (line != null) { SupportClass.Tokenizer st = new SupportClass.Tokenizer(line); System.String command = st.NextToken(); if ("!Header".Equals(command)) { //logger.warn("Ignoring header"); } else if ("!Info".Equals(command)) { //logger.warn("Ignoring info"); } else if ("!Atoms".Equals(command)) { //logger.info("Reading atom block"); // determine number of atoms to read try { numberOfAtoms = System.Int32.Parse(st.NextToken()); //logger.debug(" #atoms: " + numberOfAtoms); atoms = new int[numberOfAtoms]; atomxs = new double[numberOfAtoms]; atomys = new double[numberOfAtoms]; atomzs = new double[numberOfAtoms]; atomcharges = new double[numberOfAtoms]; for (int i = 0; i < numberOfAtoms; i++) { line = input.ReadLine(); SupportClass.Tokenizer atomInfoFields = new SupportClass.Tokenizer(line); int atomID = System.Int32.Parse(atomInfoFields.NextToken()); atoms[atomID] = System.Int32.Parse(atomInfoFields.NextToken()); //logger.debug("Set atomic number of atom (" + atomID + ") to: " + atoms[atomID]); } } catch (System.Exception exception) { //logger.error("Error while reading Atoms block"); //logger.debug(exception); } } else if ("!Bonds".Equals(command)) { //logger.info("Reading bond block"); try { // determine number of bonds to read numberOfBonds = System.Int32.Parse(st.NextToken()); bondatomid1 = new int[numberOfAtoms]; bondatomid2 = new int[numberOfAtoms]; bondorder = new int[numberOfAtoms]; for (int i = 0; i < numberOfBonds; i++) { line = input.ReadLine(); SupportClass.Tokenizer bondInfoFields = new SupportClass.Tokenizer(line); bondatomid1[i] = System.Int32.Parse(bondInfoFields.NextToken()); bondatomid2[i] = System.Int32.Parse(bondInfoFields.NextToken()); System.String order = bondInfoFields.NextToken(); if ("D".Equals(order)) { bondorder[i] = 2; } else if ("S".Equals(order)) { bondorder[i] = 1; } else if ("T".Equals(order)) { bondorder[i] = 3; } else { // ignore order, i.e. set to single //logger.warn("Unrecognized bond order, using single bond instead. Found: " + order); bondorder[i] = 1; } } } catch (System.Exception exception) { //logger.error("Error while reading Bonds block"); //logger.debug(exception); } } else if ("!Coord".Equals(command)) { //logger.info("Reading coordinate block"); try { for (int i = 0; i < numberOfAtoms; i++) { line = input.ReadLine(); SupportClass.Tokenizer atomInfoFields = new SupportClass.Tokenizer(line); int atomID = System.Int32.Parse(atomInfoFields.NextToken()); double x = System.Double.Parse(atomInfoFields.NextToken()); double y = System.Double.Parse(atomInfoFields.NextToken()); double z = System.Double.Parse(atomInfoFields.NextToken()); atomxs[atomID] = x; atomys[atomID] = y; atomzs[atomID] = z; } } catch (System.Exception exception) { //logger.error("Error while reading Coord block"); //logger.debug(exception); } } else if ("!Charges".Equals(command)) { //logger.info("Reading charges block"); try { for (int i = 0; i < numberOfAtoms; i++) { line = input.ReadLine(); SupportClass.Tokenizer atomInfoFields = new SupportClass.Tokenizer(line); int atomID = System.Int32.Parse(atomInfoFields.NextToken()); double charge = System.Double.Parse(atomInfoFields.NextToken()); atomcharges[atomID] = charge; } } catch (System.Exception exception) { //logger.error("Error while reading Charges block"); //logger.debug(exception); } } else if ("!End".Equals(command)) { //logger.info("Found end of file"); // Store atoms IAtomContainer container = model.Builder.newAtomContainer(); for (int i = 0; i < numberOfAtoms; i++) { try { IAtom atom = model.Builder.newAtom(IsotopeFactory.getInstance(container.Builder).getElementSymbol(atoms[i])); atom.AtomicNumber = atoms[i]; atom.setPoint3d(new Point3d(atomxs[i], atomys[i], atomzs[i])); atom.setCharge(atomcharges[i]); container.addAtom(atom); //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.debug("Stored atom: " + atom); } catch (System.Exception exception) { //logger.error("Cannot create an atom with atomic number: " + atoms[i]); //logger.debug(exception); } } // Store bonds for (int i = 0; i < numberOfBonds; i++) { container.addBond(bondatomid1[i], bondatomid2[i], bondorder[i]); } ISetOfMolecules moleculeSet = model.Builder.newSetOfMolecules(); moleculeSet.addMolecule(model.Builder.newMolecule(container)); model.SetOfMolecules = moleculeSet; return model; } else { //logger.warn("Skipping line: " + line); } line = input.ReadLine(); } } catch (System.Exception exception) { //logger.error("Error while reading file"); //logger.debug(exception); } // this should not happen, file is lacking !End command return null; }
/// <summary> Private method that actually parses the input to read a ChemFile /// object. In its current state it is able to read all the molecules /// (if more than one is present) in the specified HIN file. These are /// placed in a SetOfMolecules object which in turn is placed in a ChemModel /// which in turn is placed in a ChemSequence object and which is finally /// placed in a ChemFile object and returned to the user. /// /// </summary> /// <returns> A ChemFile containing the data parsed from input. /// </returns> private IChemFile readChemFile(IChemFile file) { IChemSequence chemSequence = file.Builder.newChemSequence(); IChemModel chemModel = file.Builder.newChemModel(); ISetOfMolecules setOfMolecules = file.Builder.newSetOfMolecules(); System.String info; SupportClass.Tokenizer tokenizer; try { System.String line; // read in header info while (true) { line = input.ReadLine(); if (line.IndexOf("mol ") == 0) { info = getMolName(line); break; } } // start the actual molecule data - may be multiple molecule line = input.ReadLine(); while (true) { if (line == null) break; // end of file if (line.IndexOf(';') == 0) continue; // comment line if (line.IndexOf("mol ") == 0) { info = getMolName(line); line = input.ReadLine(); } IMolecule m = file.Builder.newMolecule(); m.setProperty(CDKConstants.TITLE, info); // Each elemnt of cons is an ArrayList of length 3 which stores // the start and end indices and bond order of each bond // found in the HIN file. Before adding bonds we need to reduce // the number of bonds so as not to count the same bond twice System.Collections.ArrayList cons = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // read data for current molecule int atomSerial = 0; while (true) { if (line.IndexOf("endmol ") >= 0) { break; } if (line.IndexOf(';') == 0) continue; // comment line tokenizer = new SupportClass.Tokenizer(line, " "); int ntoken = tokenizer.Count; System.String[] toks = new System.String[ntoken]; for (int i = 0; i < ntoken; i++) toks[i] = tokenizer.NextToken(); System.String sym = new System.Text.StringBuilder(toks[3]).ToString(); double charge = System.Double.Parse(toks[6]); double x = System.Double.Parse(toks[7]); double y = System.Double.Parse(toks[8]); double z = System.Double.Parse(toks[9]); int nbond = System.Int32.Parse(toks[10]); IAtom atom = file.Builder.newAtom(sym, new Point3d(x, y, z)); atom.setCharge(charge); for (int j = 11; j < (11 + nbond * 2); j += 2) { double bo = 1; int s = System.Int32.Parse(toks[j]) - 1; // since atoms start from 1 in the file char bt = toks[j + 1][0]; switch (bt) { case 's': bo = 1; break; case 'd': bo = 2; break; case 't': bo = 3; break; case 'a': bo = 1.5; break; } System.Collections.ArrayList ar = new System.Collections.ArrayList(3); ar.Add((System.Int32)atomSerial); ar.Add((System.Int32)s); ar.Add((double)bo); cons.Add(ar); } m.addAtom(atom); atomSerial++; line = input.ReadLine(); } // before storing the molecule lets include the connections // First we reduce the number of bonds stored, since we have // stored both, say, C1-H1 and H1-C1. System.Collections.ArrayList blist = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); for (int i = 0; i < cons.Count; i++) { System.Collections.ArrayList ar = (System.Collections.ArrayList)cons[i]; // make a reversed list System.Collections.ArrayList arev = new System.Collections.ArrayList(3); arev.Add(ar[1]); arev.Add(ar[0]); arev.Add(ar[2]); // Now see if ar or arev are already in blist if (blist.Contains(ar) || blist.Contains(arev)) continue; else blist.Add(ar); } // now just store all the bonds we have for (int i = 0; i < blist.Count; i++) { System.Collections.ArrayList ar = (System.Collections.ArrayList)blist[i]; int s = ((System.Int32)ar[0]); int e = ((System.Int32)ar[1]); double bo = ((System.Double)ar[2]); m.addBond(s, e, bo); } setOfMolecules.addMolecule(m); line = input.ReadLine(); // read in the 'mol N' } // got all the molecule in the HIN file (hopefully!) chemModel.SetOfMolecules = setOfMolecules; chemSequence.addChemModel(chemModel); file.addChemSequence(chemSequence); } catch (System.IO.IOException e) { // should make some noise now file = null; } return file; }
/// <summary> Read a Reaction from a file in MDL RXN format /// /// </summary> /// <returns> The Reaction that was read from the MDL file. /// </returns> private IReaction readReaction(IChemObjectBuilder builder) { IReaction reaction = builder.newReaction(); try { input.ReadLine(); // first line should be $RXN input.ReadLine(); // second line input.ReadLine(); // third line input.ReadLine(); // fourth line } catch (System.IO.IOException exception) { //logger.debug(exception); throw new CDKException("Error while reading header of RXN file", exception); } int reactantCount = 0; int productCount = 0; try { System.String countsLine = input.ReadLine(); /* this line contains the number of reactants and products */ SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(countsLine); reactantCount = System.Int32.Parse(tokenizer.NextToken()); //logger.info("Expecting " + reactantCount + " reactants in file"); productCount = System.Int32.Parse(tokenizer.NextToken()); //logger.info("Expecting " + productCount + " products in file"); } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Error while counts line of RXN file", exception); } // now read the reactants try { for (int i = 1; i <= reactantCount; i++) { System.Text.StringBuilder molFile = new System.Text.StringBuilder(); input.ReadLine(); // announceMDLFileLine System.String molFileLine = ""; do { molFileLine = input.ReadLine(); molFile.Append(molFileLine); molFile.Append("\n"); } while (!molFileLine.Equals("M END")); // read MDL molfile content MDLReader reader = new MDLReader(new StreamReader(molFile.ToString())); IMolecule reactant = (IMolecule)reader.read(builder.newMolecule()); // add reactant reaction.addReactant(reactant); } } catch (CDKException exception) { // rethrow exception from MDLReader throw exception; } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Error while reading reactant", exception); } // now read the products try { for (int i = 1; i <= productCount; i++) { System.Text.StringBuilder molFile = new System.Text.StringBuilder(); input.ReadLine(); // String announceMDLFileLine = System.String molFileLine = ""; do { molFileLine = input.ReadLine(); molFile.Append(molFileLine); molFile.Append("\n"); } while (!molFileLine.Equals("M END")); // read MDL molfile content MDLReader reader = new MDLReader(new StreamReader(molFile.ToString())); IMolecule product = (IMolecule)reader.read(builder.newMolecule()); // add reactant reaction.addProduct(product); } } catch (CDKException exception) { // rethrow exception from MDLReader throw exception; } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Error while reading products", exception); } // now try to map things, if wanted //logger.info("Reading atom-atom mapping from file"); // distribute all atoms over two AtomContainer's IAtomContainer reactingSide = builder.newAtomContainer(); IMolecule[] molecules = reaction.Reactants.Molecules; for (int i = 0; i < molecules.Length; i++) { reactingSide.add(molecules[i]); } IAtomContainer producedSide = builder.newAtomContainer(); molecules = reaction.Products.Molecules; for (int i = 0; i < molecules.Length; i++) { producedSide.add(molecules[i]); } // map the atoms int mappingCount = 0; IAtom[] reactantAtoms = reactingSide.Atoms; IAtom[] producedAtoms = producedSide.Atoms; for (int i = 0; i < reactantAtoms.Length; i++) { for (int j = 0; j < producedAtoms.Length; j++) { if (reactantAtoms[i].ID != null && reactantAtoms[i].ID.Equals(producedAtoms[j].ID)) { reaction.addMapping(builder.newMapping(reactantAtoms[i], producedAtoms[j])); mappingCount++; break; } } } //logger.info("Mapped atom pairs: " + mappingCount); return reaction; }
public virtual void endElement(CMLStack xpath, System.String uri, System.String name, System.String raw) { ////logger.debug("EndElement: ", name); System.String cData = currentChars; if ("bond".Equals(name)) { if (!stereoGiven) bondStereo.Add(""); if (bondStereo.Count > bondDictRefs.Count) bondDictRefs.Add(null); } else if ("atom".Equals(name)) { if (atomCounter > eltitles.Count) { eltitles.Add(null); } if (atomCounter > hCounts.Count) { /* while strictly undefined, assume zero implicit hydrogens when no number is given */ hCounts.Add("0"); } if (atomCounter > atomDictRefs.Count) { atomDictRefs.Add(null); } if (atomCounter > isotope.Count) { isotope.Add(null); } if (atomCounter > spinMultiplicities.Count) { spinMultiplicities.Add(null); } if (atomCounter > formalCharges.Count) { /* while strictly undefined, assume zero implicit hydrogens when no number is given */ formalCharges.Add("0"); } /* It may happen that not all atoms have associated 2D or 3D coordinates. accept that */ if (atomCounter > x2.Count && x2.Count != 0) { /* apparently, the previous atoms had atomic coordinates, add 'null' for this atom */ x2.Add(null); y2.Add(null); } if (atomCounter > x3.Count && x3.Count != 0) { /* apparently, the previous atoms had atomic coordinates, add 'null' for this atom */ x3.Add(null); y3.Add(null); z3.Add(null); } if (atomCounter > xfract.Count && xfract.Count != 0) { /* apparently, the previous atoms had atomic coordinates, add 'null' for this atom */ xfract.Add(null); yfract.Add(null); zfract.Add(null); } } else if ("molecule".Equals(name)) { storeData(); cdo.endObject("Molecule"); } else if ("crystal".Equals(name)) { if (crystalScalar > 0) { // convert unit cell parameters to cartesians Vector3d[] axes = CrystalGeometryTools.notionalToCartesian(unitcellparams[0], unitcellparams[1], unitcellparams[2], unitcellparams[3], unitcellparams[4], unitcellparams[5]); aAxis = axes[0]; bAxis = axes[1]; cAxis = axes[2]; cartesianAxesSet = true; cdo.startObject("a-axis"); cdo.setObjectProperty("a-axis", "x", aAxis.x.ToString()); cdo.setObjectProperty("a-axis", "y", aAxis.y.ToString()); cdo.setObjectProperty("a-axis", "z", aAxis.z.ToString()); cdo.endObject("a-axis"); cdo.startObject("b-axis"); cdo.setObjectProperty("b-axis", "x", bAxis.x.ToString()); cdo.setObjectProperty("b-axis", "y", bAxis.y.ToString()); cdo.setObjectProperty("b-axis", "z", bAxis.z.ToString()); cdo.endObject("b-axis"); cdo.startObject("c-axis"); cdo.setObjectProperty("c-axis", "x", cAxis.x.ToString()); cdo.setObjectProperty("c-axis", "y", cAxis.y.ToString()); cdo.setObjectProperty("c-axis", "z", cAxis.z.ToString()); cdo.endObject("c-axis"); } else { ////logger.error("Could not find crystal unit cell parameters"); } cdo.endObject("Crystal"); } else if ("list".Equals(name)) { cdo.endObject("SetOfMolecules"); } else if ("coordinate3".Equals(name)) { if (BUILTIN.Equals("xyz3")) { ////logger.debug("New coord3 xyz3 found: ", currentChars); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(currentChars); x3.Add(st.NextToken()); y3.Add(st.NextToken()); z3.Add(st.NextToken()); ////logger.debug("coord3 x3.length: ", x3.Count); ////logger.debug("coord3 y3.length: ", y3.Count); ////logger.debug("coord3 z3.length: ", z3.Count); } catch (System.Exception exception) { ////logger.error("CMLParsing error while setting coordinate3!"); ////logger.debug(exception); } } else { ////logger.warn("Unknown coordinate3 BUILTIN: " + BUILTIN); } } else if ("string".Equals(name)) { if (BUILTIN.Equals("elementType")) { ////logger.debug("Element: ", cData.Trim()); elsym.Add(cData); } else if (BUILTIN.Equals("atomRef")) { curRef++; ////logger.debug("Bond: ref #", curRef); if (curRef == 1) { bondARef1.Add(cData.Trim()); } else if (curRef == 2) { bondARef2.Add(cData.Trim()); } } else if (BUILTIN.Equals("order")) { ////logger.debug("Bond: order ", cData.Trim()); order.Add(cData.Trim()); } else if (BUILTIN.Equals("formalCharge")) { // NOTE: this combination is in violation of the CML DTD!!! ////logger.warn("formalCharge BUILTIN accepted but violating CML DTD"); ////logger.debug("Charge: ", cData.Trim()); System.String charge = cData.Trim(); if (charge.StartsWith("+") && charge.Length > 1) { charge = charge.Substring(1); } formalCharges.Add(charge); } } else if ("float".Equals(name)) { if (BUILTIN.Equals("x3")) { x3.Add(cData.Trim()); } else if (BUILTIN.Equals("y3")) { y3.Add(cData.Trim()); } else if (BUILTIN.Equals("z3")) { z3.Add(cData.Trim()); } else if (BUILTIN.Equals("x2")) { x2.Add(cData.Trim()); } else if (BUILTIN.Equals("y2")) { y2.Add(cData.Trim()); } else if (BUILTIN.Equals("order")) { // NOTE: this combination is in violation of the CML DTD!!! order.Add(cData.Trim()); } else if (BUILTIN.Equals("charge") || BUILTIN.Equals("partialCharge")) { partialCharges.Add(cData.Trim()); } } else if ("integer".Equals(name)) { if (BUILTIN.Equals("formalCharge")) { formalCharges.Add(cData.Trim()); } } else if ("coordinate2".Equals(name)) { if (BUILTIN.Equals("xy2")) { ////logger.debug("New coord2 xy2 found.", cData); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); x2.Add(st.NextToken()); y2.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 175, 1); } } } else if ("stringArray".Equals(name)) { if (BUILTIN.Equals("id") || BUILTIN.Equals("atomId") || BUILTIN.Equals("atomID")) { // invalid according to CML1 DTD but found in OpenBabel 1.x output try { bool countAtoms = (atomCounter == 0) ? true : false; SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { if (countAtoms) { atomCounter++; } System.String token = st.NextToken(); ////logger.debug("StringArray (Token): ", token); elid.Add(token); } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 186, 1); } } else if (BUILTIN.Equals("elementType")) { try { bool countAtoms = (atomCounter == 0) ? true : false; SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { if (countAtoms) { atomCounter++; } elsym.Add(st.NextToken()); } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 194, 1); } } else if (BUILTIN.Equals("atomRefs")) { curRef++; ////logger.debug("New atomRefs found: ", curRef); try { bool countBonds = (bondCounter == 0) ? true : false; SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { if (countBonds) { bondCounter++; } System.String token = st.NextToken(); ////logger.debug("Token: ", token); if (curRef == 1) { bondARef1.Add(token); } else if (curRef == 2) { bondARef2.Add(token); } } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 194, 1); } } else if (BUILTIN.Equals("atomRef")) { curRef++; ////logger.debug("New atomRef found: ", curRef); // this is CML1 stuff, we get things like: /* <bondArray> <stringArray builtin="atomRef">a2 a2 a2 a2 a3 a3 a4 a4 a5 a6 a7 a9</stringArray> <stringArray builtin="atomRef">a9 a11 a12 a13 a5 a4 a6 a9 a7 a8 a8 a10</stringArray> <stringArray builtin="order">1 1 1 1 2 1 2 1 1 1 2 2</stringArray> </bondArray> */ try { bool countBonds = (bondCounter == 0) ? true : false; SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { if (countBonds) { bondCounter++; } System.String token = st.NextToken(); ////logger.debug("Token: ", token); if (curRef == 1) { bondARef1.Add(token); } else if (curRef == 2) { bondARef2.Add(token); } } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 194, 1); } } else if (BUILTIN.Equals("order")) { ////logger.debug("New bond order found."); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { System.String token = st.NextToken(); ////logger.debug("Token: ", token); order.Add(token); } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 194, 1); } } } else if ("integerArray".Equals(name)) { ////logger.debug("IntegerArray: builtin = ", BUILTIN); if (BUILTIN.Equals("formalCharge")) { try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { System.String token = st.NextToken(); ////logger.debug("Charge added: ", token); formalCharges.Add(token); } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 205, 1); } } } else if ("scalar".Equals(name)) { if (xpath.ToString().EndsWith("crystal/scalar/")) { ////logger.debug("Going to set a crystal parameter: " + crystalScalar, " to ", cData); try { unitcellparams[crystalScalar - 1] = System.Double.Parse(cData.Trim()); } catch (System.FormatException exception) { ////logger.error("Content must a float: " + cData); } } else { if (xpath.ToString().EndsWith("bond/scalar/")) { if (DICTREF.Equals("mdl:stereo")) { bondStereo.Add(cData.Trim()); stereoGiven = true; } } else { if (xpath.ToString().EndsWith("atom/scalar/")) { if (DICTREF.Equals("cdk:partialCharge")) { partialCharges.Add(cData.Trim()); } } else { if (xpath.ToString().EndsWith("molecule/scalar/")) { if (DICTREF.Equals("pdb:id")) { cdo.setObjectProperty("Molecule", DICTREF, cData); } } else { ////logger.warn("Ignoring scalar: " + xpath); } } } } } else if ("floatArray".Equals(name)) { if (BUILTIN.Equals("x3")) { try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) x3.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 205, 1); } } else if (BUILTIN.Equals("y3")) { try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) y3.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 213, 1); } } else if (BUILTIN.Equals("z3")) { try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) z3.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 221, 1); } } else if (BUILTIN.Equals("x2")) { ////logger.debug("New floatArray found."); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) x2.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 205, 1); } } else if (BUILTIN.Equals("y2")) { ////logger.debug("New floatArray found."); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) y2.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 454, 1); } } else if (BUILTIN.Equals("partialCharge")) { ////logger.debug("New floatArray with partial charges found."); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) partialCharges.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 462, 1); } } } else if ("basic".Equals(name)) { // assuming this is the child element of <identifier> this.inchi = cData; } else if ("name".Equals(name)) { if (xpath.ToString().EndsWith("molecule/name/")) { cdo.setObjectProperty("Molecule", DICTREF, cData); } } else { ////logger.warn("Skipping element: " + name); } currentChars = ""; BUILTIN = ""; elementTitle = ""; }
private void processAnnotation(System.String field, System.String value_Renamed, Reaction reaction) { //logger.debug("Annote: ", field, "=", value_Renamed); if (field.Equals("RxnAtts") || field.Equals("RxnType")) { // reaction attributes System.String dictionary = "macie"; if (value_Renamed.Equals("Acid") || value_Renamed.Equals("Base")) { dictionary = "chemical"; } addDictRefedAnnotation(reaction, "Attributes", value_Renamed); } else if (field.Equals("ResiduesPresent") || field.Equals("GroupTransferred") || field.Equals("BondFormed") || field.Equals("ReactiveCentres") || field.Equals("BondCleaved") || field.Equals("BondFormed") || field.Equals("Products") || field.Equals("ResiduesPresent")) { reaction.setProperty(new DictRef("macie:" + field, value_Renamed), value_Renamed); } else if (field.Equals("Reversible")) { if (value_Renamed.ToUpper().Equals("yes".ToUpper())) { reaction.Direction = IReaction_Fields.BIDIRECTIONAL; addDictRefedAnnotation(reaction, "ReactionType", "ReversibleReaction"); } } else if (field.Equals("OverallReactionType")) { SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(value_Renamed, ","); int i = 0; while (tokenizer.HasMoreTokens()) { System.String token = tokenizer.NextToken(); i++; reaction.setProperty(DictionaryDatabase.DICTREFPROPERTYNAME + ":field:overallReactionType:" + i, "macie:" + token.ToLower()); } } else { Match residueLocatorMatcher = residueLocator.Match(field); if (residueLocatorMatcher.Success) { //logger.debug("Found residueLocator: ", field); IAtom[] atoms = ReactionManipulator.getAllInOneContainer(reaction).Atoms; bool found = false; //logger.debug("Searching for given residueLocator through #atom: ", atoms.Length); //logger.debug("Taken from reaction ", reaction.ID); for (int i = 0; (i < atoms.Length && !found); i++) { if (atoms[i] is PseudoAtom) { // that is what we are looking for PseudoAtom atom = (PseudoAtom)atoms[i]; if (atom.Label.Equals(field)) { // we have a hit, now mark Atom with dict refs addDictRefedAnnotation(atom, "ResidueRole", value_Renamed); found = true; } } } if (!found) { //logger.error("MACiE annotation mentions a residue that does not exist: " + field); } } else { //logger.error("Did not parse annotation: ", field); } } }
private void addDictRefedAnnotation(IChemObject object_Renamed, System.String type, System.String values) { SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(values, ","); while (tokenizer.HasMoreTokens()) { System.String token = tokenizer.NextToken(); object_Renamed.setProperty(new DictRef("macie:" + type, token), token); //logger.debug("Added dict ref ", token, " to ", object_Renamed.GetType().FullName); } }
/// <summary> Select the theory and basis set from the first archive line. /// /// </summary> /// <param name="line">Description of the Parameter /// </param> /// <returns> Description of the Return Value /// </returns> private System.String parseLevelOfTheory(System.String line) { System.Text.StringBuilder summary = new System.Text.StringBuilder(); summary.Append(line); try { do { line = input.ReadLine().Trim(); summary.Append(line); } while (!(line.IndexOf("@") >= 0)); } catch (System.Exception exc) { //logger.debug("syntax problem while parsing summary of g98 section: "); //logger.debug(exc); } //logger.debug("parseLoT(): " + summary.ToString()); SupportClass.Tokenizer st1 = new SupportClass.Tokenizer(summary.ToString(), "\\"); // Must contain at least 6 tokens if (st1.Count < 6) { return null; } // Skip first four tokens for (int i = 0; i < 4; ++i) { st1.NextToken(); } return st1.NextToken() + "/" + st1.NextToken(); }
/// <summary> Reads a set of vibrations into ChemFrame. /// /// </summary> /// <param name="model"> Description of the Parameter /// </param> /// <exception cref="IOException"> if an I/O error occurs /// </exception> // private void readFrequencies(IChemModel model) throws IOException // { /* * FIXME: this is yet to be ported * String line; * line = input.readLine(); * line = input.readLine(); * line = input.readLine(); * line = input.readLine(); * line = input.readLine(); * while ((line != null) && line.startsWith(" Frequencies --")) { * Vector currentVibs = new Vector(); * StringReader vibValRead = new StringReader(line.substring(15)); * StreamTokenizer token = new StreamTokenizer(vibValRead); * while (token.nextToken() != StreamTokenizer.TT_EOF) { * Vibration vib = new Vibration(Double.toString(token.nval)); * currentVibs.addElement(vib); * } * line = input.readLine(); * line = input.readLine(); * line = input.readLine(); * line = input.readLine(); * line = input.readLine(); * line = input.readLine(); * for (int i = 0; i < frame.getAtomCount(); ++i) { * line = input.readLine(); * StringReader vectorRead = new StringReader(line); * token = new StreamTokenizer(vectorRead); * token.nextToken(); * / ignore first token * token.nextToken(); * / ignore second token * for (int j = 0; j < currentVibs.size(); ++j) { * double[] v = new double[3]; * if (token.nextToken() == StreamTokenizer.TT_NUMBER) { * v[0] = token.nval; * } else { * throw new IOException("Error reading frequency"); * } * if (token.nextToken() == StreamTokenizer.TT_NUMBER) { * v[1] = token.nval; * } else { * throw new IOException("Error reading frequency"); * } * if (token.nextToken() == StreamTokenizer.TT_NUMBER) { * v[2] = token.nval; * } else { * throw new IOException("Error reading frequency"); * } * ((Vibration) currentVibs.elementAt(j)).addAtomVector(v); * } * } * for (int i = 0; i < currentVibs.size(); ++i) { * frame.addVibration((Vibration) currentVibs.elementAt(i)); * } * line = input.readLine(); * line = input.readLine(); * line = input.readLine(); * } */ // } /// <summary> Reads NMR nuclear shieldings. /// /// </summary> /// <param name="model"> Description of the Parameter /// </param> /// <param name="labelLine">Description of the Parameter /// </param> /// <throws> CDKException Description of the Exception </throws> private void readNMRData(IChemModel model, System.String labelLine) { IAtomContainer ac = ChemModelManipulator.getAllInOneContainer(model); // Determine label for properties System.String label; if (labelLine.IndexOf("Diamagnetic") >= 0) { label = "Diamagnetic Magnetic shielding (Isotropic)"; } else if (labelLine.IndexOf("Paramagnetic") >= 0) { label = "Paramagnetic Magnetic shielding (Isotropic)"; } else { label = "Magnetic shielding (Isotropic)"; } int atomIndex = 0; for (int i = 0; i < atomCount; ++i) { try { System.String line = input.ReadLine().Trim(); while (line.IndexOf("Isotropic") < 0) { if (line == null) { return; } line = input.ReadLine().Trim(); } SupportClass.Tokenizer st1 = new SupportClass.Tokenizer(line); // Find Isotropic label while (st1.HasMoreTokens()) { if (st1.NextToken().Equals("Isotropic")) { break; } } // Find Isotropic value while (st1.HasMoreTokens()) { if (st1.NextToken().Equals("=")) break; } double shielding = System.Double.Parse(st1.NextToken()); //logger.info("Type of shielding: " + label); ac.getAtomAt(atomIndex).setProperty(CDKConstants.ISOTROPIC_SHIELDING, (System.Object)shielding); ++atomIndex; } catch (System.Exception exc) { //logger.debug("failed to read line from gaussian98 file where I expected one."); } } }
public override void characterData(CMLStack xpath, char[] ch, int start, int length) { System.String s = new System.String(ch, start, length).Trim(); //logger.debug("Start PMP chardata (" + CurrentElement + ") :" + s); //logger.debug(" ElTitle: " + elementTitle); if (xpath.ToString().EndsWith("string/") && BUILTIN.Equals("spacegroup")) { System.String sg = "P1"; // standardize space group names (see Crystal.java) if ("P 21 21 21 (1)".Equals(s)) { sg = "P 2_1 2_1 2_1"; } cdo.setObjectProperty("Crystal", "spacegroup", sg); } else { if (xpath.ToString().EndsWith("floatArray/") && (elementTitle.Equals("a") || elementTitle.Equals("b") || elementTitle.Equals("c"))) { System.String axis = elementTitle + "-axis"; cdo.startObject(axis); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(s); //logger.debug("Tokens: " + st.Count); if (st.Count > 2) { System.String token = st.NextToken(); //logger.debug("FloatArray (Token): " + token); cdo.setObjectProperty(axis, "x", token); token = st.NextToken(); //logger.debug("FloatArray (Token): " + token); cdo.setObjectProperty(axis, "y", token); token = st.NextToken(); //logger.debug("FloatArray (Token): " + token); cdo.setObjectProperty(axis, "z", token); } else { //logger.debug("PMP Convention error: incorrect number of cell axis fractions!\n"); } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //logger.debug("PMP Convention error: " + e.ToString()); } cdo.endObject(axis); } else { base.characterData(xpath, ch, start, length); } } //logger.debug("End PMP chardata"); }
private int addArrayElementsTo(System.Collections.ArrayList toAddto, System.String array) { SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(array); int i = 0; while (tokenizer.HasMoreTokens()) { toAddto.Add(tokenizer.NextToken()); i++; } return i; }
/// <summary> Read a Reaction from a file in MDL RXN format /// /// </summary> /// <returns> The Reaction that was read from the MDL file. /// </returns> private IMolecule readMolecule(IMolecule molecule) { AtomTypeFactory atFactory = null; try { atFactory = AtomTypeFactory.getInstance("mol2_atomtypes.xml", molecule.Builder); } catch (System.Exception exception) { System.String error = "Could not instantiate an AtomTypeFactory"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } try { System.String line = input.ReadLine(); int atomCount = 0; int bondCount = 0; while (line != null) { if (line.StartsWith("@<TRIPOS>MOLECULE")) { //logger.info("Reading molecule block"); // second line has atom/bond counts? input.ReadLine(); // disregard the name line System.String counts = input.ReadLine(); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(counts); try { atomCount = System.Int32.Parse(tokenizer.NextToken()); } catch (System.FormatException nfExc) { System.String error = "Error while reading atom count from MOLECULE block"; //logger.error(error); //logger.debug(nfExc); throw new CDKException(error, nfExc); } if (tokenizer.HasMoreTokens()) { try { bondCount = System.Int32.Parse(tokenizer.NextToken()); } catch (System.FormatException nfExc) { System.String error = "Error while reading atom and bond counts"; //logger.error(error); //logger.debug(nfExc); throw new CDKException(error, nfExc); } } else { bondCount = 0; } //logger.info("Reading #atoms: ", atomCount); //logger.info("Reading #bonds: ", bondCount); //logger.warn("Not reading molecule qualifiers"); } else if (line.StartsWith("@<TRIPOS>ATOM")) { //logger.info("Reading atom block"); for (int i = 0; i < atomCount; i++) { line = input.ReadLine().Trim(); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line); tokenizer.NextToken(); // disregard the id token System.String nameStr = tokenizer.NextToken(); System.String xStr = tokenizer.NextToken(); System.String yStr = tokenizer.NextToken(); System.String zStr = tokenizer.NextToken(); System.String atomTypeStr = tokenizer.NextToken(); IAtomType atomType = atFactory.getAtomType(atomTypeStr); if (atomType == null) { atomType = atFactory.getAtomType("X"); //logger.error("Could not find specified atom type: ", atomTypeStr); } IAtom atom = molecule.Builder.newAtom("X"); atom.ID = nameStr; atom.AtomTypeName = atomTypeStr; atFactory.configure(atom); try { double x = System.Double.Parse(xStr); double y = System.Double.Parse(yStr); double z = System.Double.Parse(zStr); atom.setPoint3d(new Point3d(x, y, z)); } catch (System.FormatException nfExc) { System.String error = "Error while reading atom coordinates"; //logger.error(error); //logger.debug(nfExc); throw new CDKException(error, nfExc); } molecule.addAtom(atom); } } else if (line.StartsWith("@<TRIPOS>BOND")) { //logger.info("Reading bond block"); for (int i = 0; i < bondCount; i++) { line = input.ReadLine(); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line); tokenizer.NextToken(); // disregard the id token System.String atom1Str = tokenizer.NextToken(); System.String atom2Str = tokenizer.NextToken(); System.String orderStr = tokenizer.NextToken(); try { int atom1 = System.Int32.Parse(atom1Str); int atom2 = System.Int32.Parse(atom2Str); double order = 0; if ("1".Equals(orderStr)) { order = CDKConstants.BONDORDER_AROMATIC; } else if ("2".Equals(orderStr)) { order = CDKConstants.BONDORDER_DOUBLE; } else if ("3".Equals(orderStr)) { order = CDKConstants.BONDORDER_TRIPLE; } else if ("am".Equals(orderStr)) { order = CDKConstants.BONDORDER_SINGLE; } else if ("ar".Equals(orderStr)) { order = CDKConstants.BONDORDER_AROMATIC; } else if ("du".Equals(orderStr)) { order = CDKConstants.BONDORDER_SINGLE; } else if ("un".Equals(orderStr)) { order = CDKConstants.BONDORDER_SINGLE; } else if ("nc".Equals(orderStr)) { // not connected order = 0; } if (order != 0) { molecule.addBond(atom1 - 1, atom2 - 1, order); } } catch (System.FormatException nfExc) { System.String error = "Error while reading bond information"; //logger.error(error); //logger.debug(nfExc); throw new CDKException(error, nfExc); } } } line = input.ReadLine(); } } catch (System.IO.IOException exception) { System.String error = "Error while reading general structure"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } return molecule; }
public virtual void startElement(CMLStack xpath, System.String uri, System.String local, System.String raw, SaxAttributesSupport atts) { System.String name = local; ////logger.debug("StartElement"); currentChars = ""; BUILTIN = ""; DICTREF = ""; for (int i = 0; i < atts.GetLength(); i++) { System.String qname = atts.GetFullName(i); if (qname.Equals("builtin")) { BUILTIN = atts.GetValue(i); ////logger.debug(name, "->BUILTIN found: ", atts.GetValue(i)); } else if (qname.Equals("dictRef")) { DICTREF = atts.GetValue(i); ////logger.debug(name, "->DICTREF found: ", atts.GetValue(i)); } else if (qname.Equals("title")) { elementTitle = atts.GetValue(i); ////logger.debug(name, "->TITLE found: ", atts.GetValue(i)); } else { ////logger.debug("Qname: ", qname); } } if ("atom".Equals(name)) { atomCounter++; for (int i = 0; i < atts.GetLength(); i++) { System.String att = atts.GetFullName(i); System.String value_Renamed = atts.GetValue(i); if (att.Equals("id")) { // this is supported in CML 1.x elid.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("elementType")) { elsym.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("title")) { eltitles.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("x2")) { x2.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("xy2")) { SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(value_Renamed); x2.Add(tokenizer.NextToken()); y2.Add(tokenizer.NextToken()); } // this is supported in CML 2.0 else if (att.Equals("xyzFract")) { SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(value_Renamed); xfract.Add(tokenizer.NextToken()); yfract.Add(tokenizer.NextToken()); zfract.Add(tokenizer.NextToken()); } // this is supported in CML 2.0 else if (att.Equals("xyz3")) { SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(value_Renamed); x3.Add(tokenizer.NextToken()); y3.Add(tokenizer.NextToken()); z3.Add(tokenizer.NextToken()); } // this is supported in CML 2.0 else if (att.Equals("y2")) { y2.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("x3")) { x3.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("y3")) { y3.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("z3")) { z3.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("xFract")) { xfract.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("yFract")) { yfract.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("zFract")) { zfract.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("formalCharge")) { formalCharges.Add(value_Renamed); } // this is supported in CML 2.0 else if (att.Equals("hydrogenCount")) { hCounts.Add(value_Renamed); } else if (att.Equals("isotope")) { isotope.Add(value_Renamed); } else if (att.Equals("dictRef")) { atomDictRefs.Add(value_Renamed); } else if (att.Equals("spinMultiplicity")) { spinMultiplicities.Add(value_Renamed); } else { ////logger.warn("Unparsed attribute: " + att); } } } else if ("atomArray".Equals(name)) { bool atomsCounted = false; for (int i = 0; i < atts.GetLength(); i++) { System.String att = atts.GetFullName(i); int count = 0; if (att.Equals("atomID")) { count = addArrayElementsTo(elid, atts.GetValue(i)); } else if (att.Equals("elementType")) { count = addArrayElementsTo(elsym, atts.GetValue(i)); } else if (att.Equals("x2")) { count = addArrayElementsTo(x2, atts.GetValue(i)); } else if (att.Equals("y2")) { count = addArrayElementsTo(y2, atts.GetValue(i)); } else if (att.Equals("x3")) { count = addArrayElementsTo(x3, atts.GetValue(i)); } else if (att.Equals("y3")) { count = addArrayElementsTo(y3, atts.GetValue(i)); } else if (att.Equals("z3")) { count = addArrayElementsTo(z3, atts.GetValue(i)); } else if (att.Equals("xFract")) { count = addArrayElementsTo(xfract, atts.GetValue(i)); } else if (att.Equals("yFract")) { count = addArrayElementsTo(yfract, atts.GetValue(i)); } else if (att.Equals("zFract")) { count = addArrayElementsTo(zfract, atts.GetValue(i)); } else { ////logger.warn("Unparsed attribute: " + att); } if (!atomsCounted) { atomCounter += count; atomsCounted = true; } } } else if ("bond".Equals(name)) { bondCounter++; for (int i = 0; i < atts.GetLength(); i++) { System.String att = atts.GetFullName(i); ////logger.debug("B2 ", att, "=", atts.GetValue(i)); if (att.Equals("id")) { bondid.Add(atts.GetValue(i)); ////logger.debug("B3 ", bondid); } else if (att.Equals("atomRefs") || att.Equals("atomRefs2")) { // this is CML 2.0 support // expect exactly two references try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(atts.GetValue(i)); bondARef1.Add((System.String)st.NextToken()); bondARef2.Add((System.String)st.NextToken()); } catch (System.Exception e) { //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("Error in CML file: ", e.Message); ////logger.debug(e); } } else if (att.Equals("order")) { // this is CML 2.0 support order.Add(atts.GetValue(i).Trim()); } else if (att.Equals("dictRef")) { bondDictRefs.Add(atts.GetValue(i).Trim()); } } stereoGiven = false; curRef = 0; } else if ("bondArray".Equals(name)) { bool bondsCounted = false; for (int i = 0; i < atts.GetLength(); i++) { System.String att = atts.GetFullName(i); int count = 0; if (att.Equals("bondID")) { count = addArrayElementsTo(bondid, atts.GetValue(i)); } else if (att.Equals("atomRefs1")) { count = addArrayElementsTo(bondARef1, atts.GetValue(i)); } else if (att.Equals("atomRefs2")) { count = addArrayElementsTo(bondARef2, atts.GetValue(i)); } else if (att.Equals("atomRef1")) { count = addArrayElementsTo(bondARef1, atts.GetValue(i)); } else if (att.Equals("atomRef2")) { count = addArrayElementsTo(bondARef2, atts.GetValue(i)); } else if (att.Equals("order")) { count = addArrayElementsTo(order, atts.GetValue(i)); } else { ////logger.warn("Unparsed attribute: " + att); } if (!bondsCounted) { bondCounter += count; bondsCounted = true; } } curRef = 0; } else if ("molecule".Equals(name)) { newMolecule(); BUILTIN = ""; cdo.startObject("Molecule"); for (int i = 0; i < atts.GetLength(); i++) { if (atts.GetFullName(i).Equals("id")) { cdo.setObjectProperty("Molecule", "id", atts.GetValue(i)); } else if (atts.GetFullName(i).Equals("dictRef")) { cdo.setObjectProperty("Molecule", "dictRef", atts.GetValue(i)); } } } else if ("crystal".Equals(name)) { newCrystalData(); cdo.startObject("Crystal"); for (int i = 0; i < atts.GetLength(); i++) { System.String att = atts.GetFullName(i); if (att.Equals("z")) { cdo.setObjectProperty("Crystal", "z", atts.GetValue(i)); } } } else if ("symmetry".Equals(name)) { for (int i = 0; i < atts.GetLength(); i++) { System.String att = atts.GetFullName(i); if (att.Equals("spaceGroup")) { cdo.setObjectProperty("Crystal", "spacegroup", atts.GetValue(i)); } } } else if ("scalar".Equals(name)) { if (xpath.ToString().EndsWith("crystal/scalar/")) crystalScalar++; } else if ("list".Equals(name)) { cdo.startObject("SetOfMolecules"); } }
public override void characterData(CMLStack xpath, char[] ch, int start, int length) { System.String s = new System.String(ch, start, length).Trim(); if (isELSYM) { elsym.Add(s); } else if (isBond) { //logger.debug("CD (bond): " + s); if (connect_root.Length > 0) { SupportClass.Tokenizer st = new SupportClass.Tokenizer(s); while (st.HasMoreTokens()) { System.String atom = (System.String)st.NextToken(); if (!atom.Equals("0")) { //logger.debug("new bond: " + connect_root + "-" + atom); cdo.startObject("Bond"); int atom1 = System.Int32.Parse(connect_root) - 1; int atom2 = System.Int32.Parse(atom) - 1; cdo.setObjectProperty("Bond", "atom1", ((System.Int32)atom1).ToString()); cdo.setObjectProperty("Bond", "atom2", ((System.Int32)atom2).ToString()); cdo.setObjectProperty("Bond", "order", "1"); cdo.endObject("Bond"); } } } } else { base.characterData(xpath, ch, start, length); } }
/// <summary> Description of the Method /// /// </summary> /// <param name="smiles"> Description of the Parameter /// </param> /// <returns> Description of the Return Value /// </returns> /// <exception cref="InvalidSmilesException"> Description of the Exception /// </exception> public virtual Reaction parseReactionSmiles(System.String smiles) { SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(smiles, ">"); System.String reactantSmiles = tokenizer.NextToken(); System.String agentSmiles = ""; System.String productSmiles = tokenizer.NextToken(); if (tokenizer.HasMoreTokens()) { agentSmiles = productSmiles; productSmiles = tokenizer.NextToken(); } Reaction reaction = new Reaction(); // add reactants IMolecule reactantContainer = parseSmiles(reactantSmiles); ISetOfMolecules reactantSet = ConnectivityChecker.partitionIntoMolecules(reactantContainer); IMolecule[] reactants = reactantSet.Molecules; for (int i = 0; i < reactants.Length; i++) { reaction.addReactant(reactants[i]); } // add reactants if (agentSmiles.Length > 0) { IMolecule agentContainer = parseSmiles(agentSmiles); ISetOfMolecules agentSet = ConnectivityChecker.partitionIntoMolecules(agentContainer); IMolecule[] agents = agentSet.Molecules; for (int i = 0; i < agents.Length; i++) { reaction.addAgent(agents[i]); } } // add products IMolecule productContainer = parseSmiles(productSmiles); ISetOfMolecules productSet = ConnectivityChecker.partitionIntoMolecules(productContainer); IMolecule[] products = productSet.Molecules; for (int i = 0; i < products.Length; i++) { reaction.addProduct(products[i]); } return reaction; }
/// <summary> Reads the atoms, coordinates and charges. /// /// <p>IMPORTANT: it does not support the atom list and its negation! /// </summary> public virtual void readAtomBlock(IAtomContainer readData) { bool foundEND = false; while (Ready && !foundEND) { System.String command = readCommand(); if ("END ATOM".Equals(command)) { // FIXME: should check wether 3D is really 2D foundEND = true; } else { //logger.debug("Parsing atom from: " + command); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(command); IAtom atom = readData.Builder.newAtom("C"); // parse the index try { System.String indexString = tokenizer.NextToken(); atom.ID = indexString; } catch (System.Exception exception) { System.String error = "Error while parsing atom index"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } // parse the element System.String element = tokenizer.NextToken(); bool isElement = false; try { isElement = IsotopeFactory.getInstance(atom.Builder).isElement(element); } catch (System.Exception exception) { throw new CDKException("Could not determine if element exists!", exception); } if (isPseudoAtom(element)) { atom = readData.Builder.newPseudoAtom(atom); } else if (isElement) { atom.Symbol = element; } else { System.String error = "Cannot parse element of type: " + element; //logger.error(error); throw new CDKException("(Possible CDK bug) " + error); } // parse atom coordinates (in Angstrom) try { System.String xString = tokenizer.NextToken(); System.String yString = tokenizer.NextToken(); System.String zString = tokenizer.NextToken(); double x = System.Double.Parse(xString); double y = System.Double.Parse(yString); double z = System.Double.Parse(zString); atom.setPoint3d(new Point3d(x, y, z)); atom.setPoint2d(new Point2d(x, y)); // FIXME: dirty! } catch (System.Exception exception) { System.String error = "Error while parsing atom coordinates"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } // atom-atom mapping System.String mapping = tokenizer.NextToken(); if (!mapping.Equals("0")) { //logger.warn("Skipping atom-atom mapping: " + mapping); } // else: default 0 is no mapping defined // the rest are key value things if (command.IndexOf("=") != -1) { System.Collections.Hashtable options = parseOptions(exhaustStringTokenizer(tokenizer)); System.Collections.IEnumerator keys = options.Keys.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' 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_javautilEnumerationhasMoreElements'" while (keys.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' 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_javautilEnumerationnextElement'" System.String key = (System.String)keys.Current; System.String value_Renamed = (System.String)options[key]; try { if (key.Equals("CHG")) { int charge = System.Int32.Parse(value_Renamed); if (charge != 0) { // zero is no charge specified atom.setFormalCharge(charge); } } else { //logger.warn("Not parsing key: " + key); } } catch (System.Exception exception) { //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'" System.String error = "Error while parsing key/value " + key + "=" + value_Renamed + ": " + exception.Message; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } } } // store atom readData.addAtom(atom); //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.debug("Added atom: " + atom); } } }
private System.String getMolName(System.String line) { if (line == null) return (""); SupportClass.Tokenizer st = new SupportClass.Tokenizer(line, " "); int ntok = st.Count; System.String[] toks = new System.String[ntok]; for (int j = 0; j < ntok; j++) { toks[j] = st.NextToken(); } if (toks.Length == 3) return (toks[2]); else return (""); }
/// <summary> Reads the bond atoms, order and stereo configuration.</summary> public virtual void readBondBlock(IAtomContainer readData) { bool foundEND = false; while (Ready && !foundEND) { System.String command = readCommand(); if ("END BOND".Equals(command)) { foundEND = true; } else { //logger.debug("Parsing bond from: " + command); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(command); IBond bond = readData.Builder.newBond(); // parse the index try { System.String indexString = tokenizer.NextToken(); bond.ID = indexString; } catch (System.Exception exception) { System.String error = "Error while parsing bond index"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } // parse the order try { System.String orderString = tokenizer.NextToken(); int order = System.Int32.Parse(orderString); if (order >= 4) { //logger.warn("Query order types are not supported (yet). File a bug if you need it"); } else { bond.Order = (double)order; } } catch (System.Exception exception) { System.String error = "Error while parsing bond index"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } // parse index atom 1 try { System.String indexAtom1String = tokenizer.NextToken(); int indexAtom1 = System.Int32.Parse(indexAtom1String); IAtom atom1 = readData.getAtomAt(indexAtom1 - 1); bond.setAtomAt(atom1, 0); } catch (System.Exception exception) { System.String error = "Error while parsing index atom 1 in bond"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } // parse index atom 2 try { System.String indexAtom2String = tokenizer.NextToken(); int indexAtom2 = System.Int32.Parse(indexAtom2String); IAtom atom2 = readData.getAtomAt(indexAtom2 - 1); bond.setAtomAt(atom2, 1); } catch (System.Exception exception) { System.String error = "Error while parsing index atom 2 in bond"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } // the rest are key=value fields if (command.IndexOf("=") != -1) { System.Collections.Hashtable options = parseOptions(exhaustStringTokenizer(tokenizer)); System.Collections.IEnumerator keys = options.Keys.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' 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_javautilEnumerationhasMoreElements'" while (keys.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' 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_javautilEnumerationnextElement'" System.String key = (System.String)keys.Current; System.String value_Renamed = (System.String)options[key]; try { if (key.Equals("CFG")) { int configuration = System.Int32.Parse(value_Renamed); if (configuration == 0) { bond.Stereo = CDKConstants.STEREO_BOND_NONE; } else if (configuration == 1) { bond.Stereo = CDKConstants.STEREO_BOND_UP; } else if (configuration == 2) { bond.Stereo = CDKConstants.STEREO_BOND_UNDEFINED; } else if (configuration == 3) { bond.Stereo = CDKConstants.STEREO_BOND_DOWN; } } else { //logger.warn("Not parsing key: " + key); } } catch (System.Exception exception) { //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'" System.String error = "Error while parsing key/value " + key + "=" + value_Renamed + ": " + exception.Message; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } } } // storing bond readData.addBond(bond); //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.debug("Added bond: " + bond); } } }
// private procedures /// <summary> Private method that actually parses the input to read a ChemFile /// object. /// /// </summary> /// <returns> A ChemFile containing the data parsed from input. /// </returns> private IChemFile readChemFile(IChemFile file) { IChemSequence chemSequence = file.Builder.newChemSequence(); int number_of_atoms = 0; SupportClass.Tokenizer tokenizer; try { System.String line = input.ReadLine(); while (input.Peek() != -1 && line != null) { // parse frame by frame tokenizer = new SupportClass.Tokenizer(line, "\t ,;"); System.String token = tokenizer.NextToken(); number_of_atoms = System.Int32.Parse(token); System.String info = input.ReadLine(); IChemModel chemModel = file.Builder.newChemModel(); ISetOfMolecules setOfMolecules = file.Builder.newSetOfMolecules(); IMolecule m = file.Builder.newMolecule(); m.setProperty(CDKConstants.TITLE, info); for (int i = 0; i < number_of_atoms; i++) { line = input.ReadLine(); if (line == null) break; if (line.StartsWith("#") && line.Length > 1) { System.Object comment = m.getProperty(CDKConstants.COMMENT); if (comment == null) { comment = ""; } //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'" comment = comment.ToString() + line.Substring(1).Trim(); m.setProperty(CDKConstants.COMMENT, comment); //logger.debug("Found and set comment: ", comment); } else { double x = 0.0f, y = 0.0f, z = 0.0f; double charge = 0.0f; tokenizer = new SupportClass.Tokenizer(line, "\t ,;"); int fields = tokenizer.Count; if (fields < 4) { // this is an error but cannot throw exception } else { System.String atomtype = tokenizer.NextToken(); //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" x = (System.Double.Parse(tokenizer.NextToken())); //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" y = (System.Double.Parse(tokenizer.NextToken())); //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" z = (System.Double.Parse(tokenizer.NextToken())); if (fields == 8) { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" charge = (System.Double.Parse(tokenizer.NextToken())); } IAtom atom = file.Builder.newAtom(atomtype, new Point3d(x, y, z)); atom.setCharge(charge); m.addAtom(atom); } } } setOfMolecules.addMolecule(m); chemModel.SetOfMolecules = setOfMolecules; chemSequence.addChemModel(chemModel); line = input.ReadLine(); } file.addChemSequence(chemSequence); } catch (System.IO.IOException e) { // should make some noise now file = null; //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("Error while reading file: ", e.Message); //logger.debug(e); } return file; }
private IReaction readReaction(IChemObjectBuilder builder) { IReaction reaction = builder.newReaction(); readLine(); // first line should be $RXN readLine(); // second line readLine(); // third line readLine(); // fourth line int reactantCount = 0; int productCount = 0; bool foundCOUNTS = false; while (Ready && !foundCOUNTS) { System.String command = readCommand(); if (command.StartsWith("COUNTS")) { SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(command); try { tokenizer.NextToken(); reactantCount = System.Int32.Parse(tokenizer.NextToken()); //logger.info("Expecting " + reactantCount + " reactants in file"); productCount = System.Int32.Parse(tokenizer.NextToken()); //logger.info("Expecting " + productCount + " products in file"); } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Error while counts line of RXN file", exception); } foundCOUNTS = true; } else { //logger.warn("Waiting for COUNTS line, but found: " + command); } } // now read the reactants for (int i = 1; i <= reactantCount; i++) { System.Text.StringBuilder molFile = new System.Text.StringBuilder(); System.String announceMDLFileLine = readCommand(); if (!announceMDLFileLine.Equals("BEGIN REACTANT")) { System.String error = "Excepted start of reactant, but found: " + announceMDLFileLine; //logger.error(error); throw new CDKException(error); } System.String molFileLine = ""; while (!molFileLine.EndsWith("END REACTANT")) { molFileLine = readLine(); molFile.Append(molFileLine); molFile.Append("\n"); }; try { // read MDL molfile content MDLV3000Reader reader = new MDLV3000Reader(new StreamReader(molFile.ToString())); IMolecule reactant = (IMolecule)reader.read(builder.newMolecule()); // add reactant reaction.addReactant(reactant); } catch (System.Exception exception) { //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'" System.String error = "Error while reading reactant: " + exception.Message; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } } // now read the products for (int i = 1; i <= productCount; i++) { System.Text.StringBuilder molFile = new System.Text.StringBuilder(); System.String announceMDLFileLine = readCommand(); if (!announceMDLFileLine.Equals("BEGIN PRODUCT")) { System.String error = "Excepted start of product, but found: " + announceMDLFileLine; //logger.error(error); throw new CDKException(error); } System.String molFileLine = ""; while (!molFileLine.EndsWith("END PRODUCT")) { molFileLine = readLine(); molFile.Append(molFileLine); molFile.Append("\n"); }; try { // read MDL molfile content MDLV3000Reader reader = new MDLV3000Reader(new StreamReader(molFile.ToString())); IMolecule product = (IMolecule)reader.read(builder.newMolecule()); // add product reaction.addProduct(product); } catch (System.Exception exception) { //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'" System.String error = "Error while reading product: " + exception.Message; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } } return reaction; }