private IChemFile readChemFile(IChemFile file) { IChemSequence seq = file.Builder.newChemSequence(); IChemModel model = file.Builder.newChemModel(); ICrystal crystal = null; int lineNumber = 0; Vector3d a, b, c; try { System.String line = input.ReadLine(); while (input.Peek() != -1 && line != null) { //logger.debug((lineNumber++) + ": ", line); if (line.StartsWith("frame:")) { //logger.debug("found new frame"); model = file.Builder.newChemModel(); crystal = file.Builder.newCrystal(); // assume the file format is correct //logger.debug("reading spacegroup"); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); crystal.SpaceGroup = line; //logger.debug("reading unit cell axes"); Vector3d axis = new Vector3d(); //logger.debug("parsing A: "); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.x = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.y = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.z = FortranFormat.atof(line); crystal.A = axis; axis = new Vector3d(); //logger.debug("parsing B: "); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.x = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.y = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.z = FortranFormat.atof(line); crystal.B = axis; axis = new Vector3d(); //logger.debug("parsing C: "); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.x = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.y = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.z = FortranFormat.atof(line); crystal.C = axis; //logger.debug("Crystal: ", crystal); a = crystal.A; b = crystal.B; c = crystal.C; //logger.debug("Reading number of atoms"); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); int atomsToRead = System.Int32.Parse(line); //logger.debug("Reading no molecules in assym unit cell"); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); int Z = System.Int32.Parse(line); crystal.Z = Z; System.String symbol; double charge; Point3d cart; for (int i = 1; i <= atomsToRead; i++) { cart = new Point3d(); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); symbol = line.Substring(0, (line.IndexOf(":")) - (0)); charge = System.Double.Parse(line.Substring(line.IndexOf(":") + 1)); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); cart.x = System.Double.Parse(line); // x line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); cart.y = System.Double.Parse(line); // y line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); cart.z = System.Double.Parse(line); // z IAtom atom = file.Builder.newAtom(symbol); atom.setCharge(charge); // convert cartesian coords to fractional Point3d frac = CrystalGeometryTools.cartesianToFractional(a, b, c, cart); atom.setFractionalPoint3d(frac); crystal.addAtom(atom); //logger.debug("Added atom: ", atom); } model.Crystal = crystal; seq.addChemModel(model); } else { //logger.debug("Format seems broken. Skipping these lines:"); while (!line.StartsWith("frame:") && input.Peek() != -1 && line != null) { line = input.ReadLine(); //logger.debug(lineNumber++ + ": ", line); } //logger.debug("Ok, resynched: found new frame"); } } file.addChemSequence(seq); } 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 message = "Error while parsing CrystClust file: " + exception.Message; //logger.error(message); //logger.debug(exception); throw new CDKException(message, exception); } return(file); }
private void processAtomLoopBlock(System.String firstLine) { int atomLabel = -1; // -1 means not found in this block int atomSymbol = -1; int atomFractX = -1; int atomFractY = -1; int atomFractZ = -1; int atomRealX = -1; int atomRealY = -1; int atomRealZ = -1; System.String line = firstLine.Trim(); int headerCount = 0; bool hasParsableInformation = false; while (line != null && line[0] == '_') { headerCount++; if (line.Equals("_atom_site_label") || line.Equals("_atom_site_label_atom_id")) { atomLabel = headerCount; hasParsableInformation = true; //logger.info("label found in col: " + atomLabel); } else if (line.StartsWith("_atom_site_fract_x")) { atomFractX = headerCount; hasParsableInformation = true; //logger.info("frac x found in col: " + atomFractX); } else if (line.StartsWith("_atom_site_fract_y")) { atomFractY = headerCount; hasParsableInformation = true; //logger.info("frac y found in col: " + atomFractY); } else if (line.StartsWith("_atom_site_fract_z")) { atomFractZ = headerCount; hasParsableInformation = true; //logger.info("frac z found in col: " + atomFractZ); } else if (line.Equals("_atom_site.Cartn_x")) { atomRealX = headerCount; hasParsableInformation = true; //logger.info("cart x found in col: " + atomRealX); } else if (line.Equals("_atom_site.Cartn_y")) { atomRealY = headerCount; hasParsableInformation = true; //logger.info("cart y found in col: " + atomRealY); } else if (line.Equals("_atom_site.Cartn_z")) { atomRealZ = headerCount; hasParsableInformation = true; //logger.info("cart z found in col: " + atomRealZ); } else if (line.Equals("_atom_site.type_symbol")) { atomSymbol = headerCount; hasParsableInformation = true; //logger.info("type_symbol found in col: " + atomSymbol); } else { //logger.warn("Ignoring atom loop block field: " + line); } line = input.ReadLine().Trim(); } if (hasParsableInformation == false) { //logger.info("No parsable info found"); skipUntilEmptyOrCommentLine(line); } else { // now that headers are parsed, read the data while (line != null && line.Length > 0 && line[0] != '#') { //logger.debug("new row"); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line); if (tokenizer.Count < headerCount) { //logger.warn("Column count mismatch; assuming continued on next line"); //logger.debug("Found #expected, #found: " + headerCount + ", " + tokenizer.Count); tokenizer = new SupportClass.Tokenizer(line + input.ReadLine()); } int colIndex = 0; // process one row IAtom atom = crystal.Builder.newAtom("C"); Point3d frac = new Point3d(); Point3d real = new Point3d(); bool hasFractional = false; bool hasCartesian = false; while (tokenizer.HasMoreTokens()) { colIndex++; System.String field = tokenizer.NextToken(); //logger.debug("Parsing col,token: " + colIndex + "=" + field); if (colIndex == atomLabel) { if (atomSymbol == -1) { // no atom symbol found, use label System.String element = extractFirstLetters(field); atom.Symbol = element; } atom.ID = field; } else if (colIndex == atomFractX) { hasFractional = true; frac.x = parseIntoDouble(field); } else if (colIndex == atomFractY) { hasFractional = true; frac.y = parseIntoDouble(field); } else if (colIndex == atomFractZ) { hasFractional = true; frac.z = parseIntoDouble(field); } else if (colIndex == atomSymbol) { atom.Symbol = field; } else if (colIndex == atomRealX) { hasCartesian = true; //logger.debug("Adding x3: " + parseIntoDouble(field)); real.x = parseIntoDouble(field); } else if (colIndex == atomRealY) { hasCartesian = true; //logger.debug("Adding y3: " + parseIntoDouble(field)); real.y = parseIntoDouble(field); } else if (colIndex == atomRealZ) { hasCartesian = true; //logger.debug("Adding x3: " + parseIntoDouble(field)); real.z = parseIntoDouble(field); } } if (hasCartesian) { Vector3d a = crystal.A; Vector3d b = crystal.B; Vector3d c = crystal.C; frac = CrystalGeometryTools.cartesianToFractional(a, b, c, real); atom.setFractionalPoint3d(frac); } if (hasFractional) { atom.setFractionalPoint3d(frac); } //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("Adding atom: " + atom); crystal.addAtom(atom); // look up next row line = input.ReadLine().Trim(); } } }
private IChemSequence readChemSequence(IChemSequence sequence) { IChemModel chemModel = sequence.Builder.newChemModel(); ICrystal crystal = null; // Get the info line (first token of the first line) //UPGRADE_ISSUE: Method 'java.io.BufferedReader.mark' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReadermark_int'" //inputBuffer.mark(255); //long pos = inputBuffer.BaseStream.Position; info = nextVASPToken(false); //System.out.println(info); //UPGRADE_ISSUE: Method 'java.io.BufferedReader.reset' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReaderreset'" //inputBuffer.reset(); // Get the number of different atom "NCLASS=X" //UPGRADE_ISSUE: Method 'java.io.BufferedReader.mark' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReadermark_int'" //inputBuffer.mark(255); nextVASPTokenFollowing("NCLASS"); ntype = System.Int32.Parse(fieldVal); //System.out.println("NCLASS= " + ntype); //UPGRADE_ISSUE: Method 'java.io.BufferedReader.reset' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReaderreset'" //inputBuffer.reset(); // Get the different atom names anames = new System.String[ntype]; nextVASPTokenFollowing("ATOM"); for (int i = 0; i < ntype; i++) { anames[i] = fieldVal; nextVASPToken(false); } // Get the number of atom of each type int[] natom_type = new int[ntype]; natom = 0; for (int i = 0; i < ntype; i++) { natom_type[i] = System.Int32.Parse(fieldVal); nextVASPToken(false); natom = natom + natom_type[i]; } // Get the representation type of the primitive vectors // only "Direct" is recognize now. representation = fieldVal; if (representation.Equals("Direct")) { //logger.info("Direct representation"); // DO NOTHING } else { throw new CDKException("This VASP file is not supported. Please contact the Jmol developpers"); } while (nextVASPToken(false) != null) { //logger.debug("New crystal started..."); crystal = sequence.Builder.newCrystal(); chemModel = sequence.Builder.newChemModel(); // Get acell for (int i = 0; i < 3; i++) { acell[i] = FortranFormat.atof(fieldVal); // all the same FIX? } // Get primitive vectors for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { nextVASPToken(false); rprim[i][j] = FortranFormat.atof(fieldVal); } } // Get atomic position int[] atomType = new int[natom]; double[][] xred = new double[natom][]; for (int i2 = 0; i2 < natom; i2++) { xred[i2] = new double[3]; } int atomIndex = 0; for (int i = 0; i < ntype; i++) { for (int j = 0; j < natom_type[i]; j++) { try { atomType[atomIndex] = IsotopeFactory.getInstance(sequence.Builder).getElement(anames[i]).AtomicNumber; } catch (System.Exception exception) { throw new CDKException("Could not determine atomic number!", exception); } //logger.debug("aname: " + anames[i]); //logger.debug("atomType: " + atomType[atomIndex]); nextVASPToken(false); xred[atomIndex][0] = FortranFormat.atof(fieldVal); nextVASPToken(false); xred[atomIndex][1] = FortranFormat.atof(fieldVal); nextVASPToken(false); xred[atomIndex][2] = FortranFormat.atof(fieldVal); atomIndex = atomIndex + 1; // FIXME: store atom } } crystal.A = new Vector3d(rprim[0][0] * acell[0], rprim[0][1] * acell[0], rprim[0][2] * acell[0]); crystal.B = new Vector3d(rprim[1][0] * acell[1], rprim[1][1] * acell[1], rprim[1][2] * acell[1]); crystal.C = new Vector3d(rprim[2][0] * acell[2], rprim[2][1] * acell[2], rprim[2][2] * acell[2]); for (int i = 0; i < atomType.Length; i++) { System.String symbol = "Du"; try { symbol = IsotopeFactory.getInstance(sequence.Builder).getElement(atomType[i]).Symbol; } catch (System.Exception exception) { throw new CDKException("Could not determine element symbol!", exception); } IAtom atom = sequence.Builder.newAtom(symbol); atom.AtomicNumber = atomType[i]; // convert fractional to cartesian double[] frac = new double[3]; frac[0] = xred[i][0]; frac[1] = xred[i][1]; frac[2] = xred[i][2]; atom.setFractionalPoint3d(new Point3d(frac[0], frac[1], frac[2])); crystal.addAtom(atom); } crystal.setProperty(CDKConstants.REMARK, info); chemModel.Crystal = crystal; //logger.info("New Frame set!"); sequence.addChemModel(chemModel); } //end while return(sequence); }