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 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); }