From: Egon W. <eg...@us...> - 2004-04-29 20:03:49
|
Update of /cvsroot/jmol/Jmol/src/org/jmol/adapter/smarter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10381/src/org/jmol/adapter/smarter Modified Files: CmlReader.java Log Message: Implemented reading of crystals in CML2 Index: CmlReader.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/jmol/adapter/smarter/CmlReader.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- CmlReader.java 29 Apr 2004 16:25:53 -0000 1.7 +++ CmlReader.java 29 Apr 2004 20:03:39 -0000 1.8 @@ -72,6 +72,7 @@ int moleculeCount = 0; Atom atom; + float[] notionalUnitcell; // the same atom array gets reused // it will grow to the maximum length; @@ -85,6 +86,20 @@ int tokenCount; String[] tokens = new String[16]; + // this param is used to keep track of the parent element type + int elementContext; + final static int UNSET = 0; + final static int CRYSTAL = 1; + final static int ATOM = 2; + + // this param is used to signal that chars should be kept + boolean keepChars; + String chars; + + // do some bookkeeping of attrib value across the element + String dictRef; + String title; + // this routine breaks out all the tokens in a string // results are placed into the tokens array void breakOutTokens(String str) { @@ -177,6 +192,22 @@ atomArray[j].modelNumber = moleculeCount; return; } + if ("crystal".equals(qName)) { + elementContext = CRYSTAL; + notionalUnitcell = new float[6]; + return; + } + if ("scalar".equals(qName)) { + for (int i=0; i<atts.getLength(); i++) { + if ("title".equals(atts.getLocalName(i))) { + title = atts.getValue(i); + } else if ("dictRef".equals(atts.getLocalName(i))) { + dictRef = atts.getValue(i); + } + } + keepChars = true; + return; + } } public void endElement(String uri, String localName, @@ -191,6 +222,39 @@ model.addAtom(atom); } atom = null; + elementContext = UNSET; + return; + } + if ("crystal".equals(qName)) { + elementContext = UNSET; + model.notionalUnitcell = notionalUnitcell; + return; + } + if ("scalar".equals(qName)) { + if (elementContext == CRYSTAL) { + System.out.println("CRYSTAL atts.title: " + title); + if ("a".equals(title)) { + notionalUnitcell[0] = parseFloat(chars); + } else if ("b".equals(title)) { + notionalUnitcell[1] = parseFloat(chars); + } else if ("c".equals(title)) { + notionalUnitcell[2] = parseFloat(chars); + } else if ("alpha".equals(title)) { + notionalUnitcell[3] = parseFloat(chars); + } else if ("beta".equals(title)) { + notionalUnitcell[4] = parseFloat(chars); + } else if ("gamma".equals(title)) { + notionalUnitcell[5] = parseFloat(chars); + } + } else if (elementContext == ATOM) { + if ("jmol:charge".equals(dictRef)) { + // atom.partialCharge = parseFloat(chars); + } + } + keepChars = false; + title = null; + dictRef = null; + chars = null; return; } if ("atomArray".equals(qName)) { @@ -205,8 +269,14 @@ } public void characters(char[] ch, int start, int length) { - // characters are not used at this time // System.out.println("End chars"); + if (keepChars) { + if (chars == null) { + chars = new String(ch, start, length); + } else { + chars += new String(ch, start, length); + } + } } // Methods for entity resolving, e.g. getting a DTD resolved |