From: <ha...@us...> - 2010-02-19 14:33:31
|
Revision: 12411 http://jmol.svn.sourceforge.net/jmol/?rev=12411&view=rev Author: hansonr Date: 2010-02-19 14:33:22 +0000 (Fri, 19 Feb 2010) Log Message: ----------- preliminary CRYSTAL reader -- requires CRYSTAL:: prefix in LOAD command. -- still needs testing Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/readers/xtal/CrystalReader.java Modified: trunk/Jmol/src/org/jmol/adapter/readers/xtal/CrystalReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/xtal/CrystalReader.java 2010-02-19 05:35:31 UTC (rev 12410) +++ trunk/Jmol/src/org/jmol/adapter/readers/xtal/CrystalReader.java 2010-02-19 14:33:22 UTC (rev 12411) @@ -31,62 +31,53 @@ import java.io.BufferedReader; /** - * + * * http://www.crystal.unito.it/ - * - * @author Pieremanuele Canepa, Room 104, FM Group - * School of Physical Sciences, Ingram Building, - * University of Kent, Canterbury, Kent, - * CT2 7NH - * United Kingdom - * + * + * @author Pieremanuele Canepa, Room 104, FM Group School of Physical Sciences, + * Ingram Building, University of Kent, Canterbury, Kent, CT2 7NH United + * Kingdom + * * @version 1.0 - * - * This version works and has been well tested on several structures! * - * TODO: Needs adaptation to be more modular and flexible - * + * This version works and has been well tested on several structures! + * + * TODO: Needs adaptation to be more modular and flexible + * */ public class CrystalReader extends AtomSetCollectionReader { - private String calculationType; - public void readAtomSetCollection(BufferedReader reader) { + private boolean isPrimitive = true; + private boolean isPolymer = false; + private boolean isSlab = false; - boolean isPeriodic = true; - boolean isFractional = true; + public void readAtomSetCollection(BufferedReader reader) { + this.reader = reader; + atomSetCollection = new AtomSetCollection("Crystal", this); - atomSetCollection = new AtomSetCollection("Crystal", this); + isPrimitive = (filter == null || filter.indexOf("conv") >= 0); + atomSetCollection.setAtomSetAuxiliaryInfo("unitCellType", (isPrimitive ? "primitive" : "conventional")); try { - this.reader = reader; - discardLinesUntilContains("* CRYSTAL"); - discardLinesUntilContains("EEEEEEEEEE"); - atomSetCollection.setCollectionName(readLine().trim()); - readLine(); - calculationType = readLine().trim(); - atomSetCollection.setAtomSetAuxiliaryInfo("calculationType", calculationType); - if (calculationType.indexOf("MOLECULAR") >= 0) { - isFractional = false; - isPeriodic = false; - } + setFractionalCoordinates(readHeader()); while (readLine() != null) { - if (line.startsWith(" SPACE GROUP ") || line.startsWith(" CORRESPONDING SPACE GROUP")) { - readSpaceGroup(); + if (line.startsWith(" LATTICE PARAMETER") && + (isPrimitive && line.contains("- PRIMITIVE") || !isPrimitive && line.contains("- CONVENTIONAL"))) { + readCellParams(); continue; } - if (line.startsWith(" LATTICE PARAMETERS (ANGSTROMS AND DEGREES) - CONVENTIONAL CELL")) { - isFractional = true; - readCellParams(); - continue; + if (isPrimitive) { + if (line + .startsWith(" COORDINATES OF THE EQUIVALENT ATOMS")) { + readFractionalCoords(); + continue; + } + } else { + if (line.startsWith(" INPUT COORDINATES")) { + readInputCoords(); + continue; + } } - if (line.startsWith(" LATTICE PARAMETER (ANGSTROMS) - CONVENTIONAL CELL")) { - isFractional = true; - readPolymerCell(); - } - if (line.startsWith(" INPUT COORDINATES")) { - readAtomCoords(isFractional, isPeriodic); - continue; - } } applySymmetryAndSetTrajectory(); @@ -95,6 +86,26 @@ } } + private boolean readHeader() throws Exception { + discardLinesUntilContains("* CRYSTAL"); + discardLinesUntilContains("EEEEEEEEEE"); + atomSetCollection.setCollectionName(readLine().trim()); + readLine(); + calculationType = readLine().trim(); + isPolymer = (calculationType.equals("POLYMER CALCULATION")); + isSlab = (calculationType.equals("SLAB CALCULATION")); + atomSetCollection.setAtomSetAuxiliaryInfo("calculationType", + calculationType); + if (calculationType.indexOf("MOLECULAR") >= 0) + return false; + if (!isPrimitive) { + readLine(); + readLine(); + readSpaceGroup(); + } + return true; + } + private void readSpaceGroup() { // SPACE GROUP (CENTROSYMMETRIC) : F M 3 M String name = line.substring(line.indexOf(":") + 1).trim(); @@ -102,35 +113,61 @@ } private void readCellParams() throws Exception { + if (isPolymer) { + float a = parseFloat(line.substring(line.indexOf("CELL") + 4)); + setUnitCell(a, 1, 1, 90, 90, 90); + return; + } readLine(); String[] tokens = getTokens(readLine()); - if (calculationType.equals("SLAB CALCULATION")) { - setUnitCell(parseFloat(tokens[0]), parseFloat(tokens[1]), 1, 90, 90, - parseFloat(tokens[2])); + if (isSlab) { + setUnitCell(parseFloat(tokens[0]), parseFloat(tokens[1]), 1, + parseFloat(tokens[3]), parseFloat(tokens[4]), parseFloat(tokens[5])); } else { - setUnitCell(parseFloat(tokens[0]), parseFloat(tokens[1]), - parseFloat(tokens[2]), parseFloat(tokens[3]), parseFloat(tokens[4]), - parseFloat(tokens[5])); + setUnitCell(parseFloat(tokens[0]), parseFloat(tokens[1]), parseFloat(tokens[2]), + parseFloat(tokens[3]), parseFloat(tokens[4]), parseFloat(tokens[5])); } } - private void readPolymerCell() { - float a = parseFloat(line.substring(line.indexOf("CELL") + 4)); - setUnitCell(a, 1, 1, 90, 90, 90); - - } + /* + COORDINATES OF THE EQUIVALENT ATOMS + (X AND Y IN FRACTIONARY UNITS, Z IN ANGSTROMS) + N. ATOM EQUIV AT. N. X Y Z - /* - INPUT COORDINATES + 1 1 1 26 FE 3.33130643604E-01 1.66339516481E-01 6.03501134235E+00 + */ + private void readFractionalCoords() throws Exception { + discardLinesUntilContains("ATOM EQUIV"); + while (readLine() != null && line.indexOf("NUMBER OF SYMM") < 0) { + if (line.length() == 0) + continue; + Atom atom = atomSetCollection.addNewAtom(); + String[] tokens = getTokens(); + int atomicNumber = parseInt(tokens[3]); + float x = parseFloat(tokens[5]); + float y = parseFloat(tokens[6]); + float z = parseFloat(tokens[7]); + if (isPolymer || isSlab) { + if (x < 0) + x += 1; + if (y < 0) + y += 1; + } + setAtomCoord(atom, x, y, z); + atom.elementSymbol = getElementSymbol(atomicNumber); + } + } - ATOM AT. N. COORDINATES - 1 12 0.000000000000E+00 0.000000000000E+00 0.000000000000E+00 - 2 8 5.000000000000E-01 5.000000000000E-01 5.000000000000E-01 - */ - private void readAtomCoords(boolean isFractional, boolean isthisPeriodic) + /* + * INPUT COORDINATES + * + * ATOM AT. N. COORDINATES + * 1 12 0.000000000000E+00 0.000000000000E+00 0.000000000000E+00 + * 2 8 5.000000000000E-01 5.000000000000E-01 5.000000000000E-01 + */ + private void readInputCoords() throws Exception { - setFractionalCoordinates(isFractional); readLine(); readLine(); while (readLine() != null && line.length() > 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |