/// <summary> /// Private method that actually parses the input to read a <see cref="IChemFile"/> object. /// </summary> /// <param name="file">the file to read from</param> /// <returns>A ChemFile containing the data parsed from input.</returns> private IChemFile ReadChemFile(IChemFile file) { IChemSequence chemSequence = file.Builder.NewChemSequence(); int number_of_atoms; try { string line = input.ReadLine(); while (line.StartsWithChar('#')) { line = input.ReadLine(); } // while (input.Ready() && line != null) { // Debug.WriteLine("lauf"); // parse frame by frame string token = Strings.Tokenize(line, '\t', ' ', ',', ';')[0]; number_of_atoms = int.Parse(token, NumberFormatInfo.InvariantInfo); string info = input.ReadLine(); IChemModel chemModel = file.Builder.NewChemModel(); var setOfMolecules = file.Builder.NewAtomContainerSet(); IAtomContainer m = file.Builder.NewAtomContainer(); m.Title = info; string[] types = new 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 //Vector3[] pos = new Vector3[number_of_atoms]; // calculated positions int i = 0; while (i < number_of_atoms) { line = input.ReadLine(); // Debug.WriteLine("line:\""+line+"\""); if (line == null) { break; } if (line.StartsWithChar('#')) { // 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; var tokens = Strings.Tokenize(line, '\t', ' ', ',', ';'); int fields = int.Parse(tokens[0], NumberFormatInfo.InvariantInfo); if (fields < Math.Min(i * 2 + 1, 7)) { // this is an error but cannot throw exception } else if (i == 0) { types[i] = tokens[1]; i++; } else if (i == 1) { types[i] = tokens[1]; d_atom[i] = int.Parse(tokens[2], NumberFormatInfo.InvariantInfo) - 1; d[i] = double.Parse(tokens[3], NumberFormatInfo.InvariantInfo); i++; } else if (i == 2) { types[i] = tokens[1]; d_atom[i] = int.Parse(tokens[2], NumberFormatInfo.InvariantInfo) - 1; d[i] = double.Parse(tokens[3], NumberFormatInfo.InvariantInfo); a_atom[i] = int.Parse(tokens[4], NumberFormatInfo.InvariantInfo) - 1; a[i] = double.Parse(tokens[5], NumberFormatInfo.InvariantInfo); i++; } else { types[i] = tokens[1]; d_atom[i] = int.Parse(tokens[2], NumberFormatInfo.InvariantInfo) - 1; d[i] = double.Parse(tokens[3], NumberFormatInfo.InvariantInfo); a_atom[i] = int.Parse(tokens[4], NumberFormatInfo.InvariantInfo) - 1; a[i] = double.Parse(tokens[5], NumberFormatInfo.InvariantInfo); da_atom[i] = int.Parse(tokens[6], NumberFormatInfo.InvariantInfo) - 1; da[i] = double.Parse(tokens[7], NumberFormatInfo.InvariantInfo); i++; } } } // calculate cartesian coordinates var cartCoords = ZMatrixTools.ZMatrixToCartesian(d, d_atom, a, a_atom, da, da_atom); for (i = 0; i < number_of_atoms; i++) { m.Atoms.Add(file.Builder.NewAtom(types[i], cartCoords[i])); } // Debug.WriteLine("molecule:"+m); setOfMolecules.Add(m); chemModel.MoleculeSet = setOfMolecules; chemSequence.Add(chemModel); line = input.ReadLine(); file.Add(chemSequence); } catch (IOException) { // should make some noise now file = null; } return(file); }
/// <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); }