Revision: 5247
Author: hansonr
Date: 2006-06-28 06:22:16 -0700 (Wed, 28 Jun 2006)
ViewCVS: http://svn.sourceforge.net/jmol/?rev=5247&view=rev
Log Message:
-----------
bob200603 mol2reader improvements
Modified Paths:
--------------
branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java
Modified: branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java
===================================================================
--- branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java
2006-06-27 14:38:48 UTC (rev 5246)
+++ branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java
2006-06-28 13:22:16 UTC (rev 5247)
@@ -29,7 +29,7 @@
import org.jmol.api.JmolAdapter;
/**
- * A MINIMAL reader for TRIPOS mol2 files.
+ * A minimal multi-file reader for TRIPOS SYBYL mol2 files.
*<p>
* <a href='http://www.tripos.com/data/support/mol2.pdf '>
* http://www.tripos.com/data/support/mol2.pdf
@@ -39,22 +39,90 @@
class Mol2Reader extends AtomSetCollectionReader {
String line;
+ int desiredModelNumber;
+ int modelNumber = 0;
+ int nAtoms = 0;
+ void initialize() {
+ desiredModelNumber = -1;
+ }
+ void initialize(int[] params) {
+ initialize();
+ if (params == null)
+ return;
+ desiredModelNumber = params[0];
+ }
+
AtomSetCollection readAtomSetCollection(BufferedReader reader)
throws Exception {
atomSetCollection = new AtomSetCollection("mol2");
line = reader.readLine();
- int atomCount = 0;
- int bondCount = 0;
- int resCount = 0;
+ modelNumber = 0;
while (line != null) {
- if (line.equals("global")) {
+ if (line.equals("@<TRIPOS>MOLECULE")) {
+ if (++modelNumber == desiredModelNumber || desiredModelNumber <= 0) {
+ try {
+ processMolecule(reader);
+ } catch (Exception e) {
+ System.out.println(e + " at line: " + line);
+ e.printStackTrace();
+ new NullPointerException();
+ }
+ if (desiredModelNumber > 0)
+ break;
+ continue;
+ }
+ }
+ line = reader.readLine();
+ }
+ return atomSetCollection;
+ }
+
+ void processMolecule(BufferedReader reader) throws Exception {
+ /* 4-6 lines:
+ ZINC02211856
+ 55 58 0 0 0
+ SMALL
+ USER_CHARGES
+ 2-diethylamino-1-[2-(2-naphthyl)-4-quinolyl]-ethanol
+
+ mol_name
+ num_atoms [num_bonds [num_subst [num_feat [num_sets]]]]
+ mol_type
+ charge_type
+ [status_bits
+ [mol_comment]]
+
+ */
+
+ String thisDataSetName = reader.readLine().trim();
+ line = reader.readLine() + " 0 0 0 0 0 0";
+ int atomCount = parseInt(line);
+ int bondCount = parseInt(line, ichNextParse);
+ int resCount = parseInt(line, ichNextParse);
+ reader.readLine();//mol_type
+ line = reader.readLine();//charge_type
+ boolean iHaveCharges = (line.indexOf("NO_CHARGES") != 0);
+ line = reader.readLine(); //optional SYBYL status
+ if (line != null && line.charAt(0) != '@') {
+ line = reader.readLine(); //optional comment
+ if (line != null && line.charAt(0) != '@') {
+ thisDataSetName += ": " + reader.readLine().trim();
line = reader.readLine();
- atomCount = parseInt(line, 0, 6);
- bondCount = parseInt(line, 6, 12);
- resCount = parseInt(line, 12, 18);
- } else if (line.equals("@<TRIPOS>ATOM")) {
- readAtoms(reader, atomCount);
+ }
+ }
+ if (atomSetCollection.currentAtomSetIndex >= 0) {
+ atomSetCollection.newAtomSet();
+ atomSetCollection.setCollectionName("<collection of "
+ + (atomSetCollection.currentAtomSetIndex + 1) + " models>");
+ } else {
+ atomSetCollection.setCollectionName(thisDataSetName);
+ }
+ logger.log(thisDataSetName);
+ while (line != null && !line.equals("@<TRIPOS>MOLECULE")) {
+ if (line.equals("@<TRIPOS>ATOM")) {
+ readAtoms(reader, atomCount, iHaveCharges);
+ atomSetCollection.setAtomSetName(thisDataSetName);
} else if (line.equals("@<TRIPOS>BOND")) {
readBonds(reader, bondCount);
} else if (line.equals("@<TRIPOS>SUBSTRUCTURE")) {
@@ -64,49 +132,50 @@
}
line = reader.readLine();
}
- return atomSetCollection;
+ nAtoms+=atomCount;
}
- void readAtoms(BufferedReader reader, int atomCount) throws Exception {
+ void readAtoms(BufferedReader reader, int atomCount, boolean iHaveCharges)
throws Exception {
// 1 Cs 0.0000 4.1230 0.0000 Cs 1 RES1 0.0000
- // 1 2 3 4 5 6
- //012345678901234567890123456789012345678901234567890123456789012345678
+ // 1 C1 7.0053 11.3096 -1.5429 C.3 1 <0> -0.1912
+ // free format, but no blank lines
for (int i = 0; i < atomCount; ++i) {
- String line = reader.readLine();
- String elementSymbol = line.substring(43, 45);
- if (elementSymbol.charAt(1) == '.')
+ Atom atom = atomSetCollection.addNewAtom();
+ line = reader.readLine();
+ String[] tokens = getTokens(line);
+ //System.out.println(tokens.length + " -" + tokens[5] + "- " + line);
+ atom.x = parseFloat(tokens[2]);
+ atom.y = parseFloat(tokens[3]);
+ atom.z = parseFloat(tokens[4]);
+ String elementSymbol = tokens[5];
+ if (elementSymbol.length() > 1 && elementSymbol.charAt(1) == '.')
elementSymbol = elementSymbol.substring(0, 1);
- float x = parseFloat(line, 13, 22);
- float y = parseFloat(line, 22, 31);
- float z = parseFloat(line, 31, 40);
- int charge = (int) parseFloat(line, 60, 68);
- Atom atom = atomSetCollection.addNewAtom();
+ if (elementSymbol.length() > 2)
+ elementSymbol = elementSymbol.substring(0, 2);
atom.elementSymbol = elementSymbol;
- atom.formalCharge = charge;
- atom.x = x;
- atom.y = y;
- atom.z = z;
+ if (iHaveCharges)
+ atom.partialCharge = parseFloat(tokens[8]);
}
}
void readBonds(BufferedReader reader, int bondCount) throws Exception {
// 6 1 42 1
- // 1 2 3 4 5 6
- //012345678901234567890123456789012345678901234567890123456789012345678
+ // free format, but no blank lines
for (int i = 0; i < bondCount; ++i) {
String line = reader.readLine();
- parseInt(line);
- int atomIndex1 = parseInt(line, ichNextParse);
- int atomIndex2 = parseInt(line, ichNextParse);
- int order = parseInt(line, ichNextParse);
+ String[] tokens = getTokens(line);
+ int atomIndex1 = parseInt(tokens[1]);
+ int atomIndex2 = parseInt(tokens[2]);
+ int order = parseInt(tokens[3]);
if (order == Integer.MIN_VALUE)
- order = JmolAdapter.ORDER_AROMATIC;
+ order = (tokens[3].equals("ar") ? JmolAdapter.ORDER_AROMATIC : 1);
atomSetCollection
- .addBond(new Bond(atomIndex1 - 1, atomIndex2 - 1, order));
+ .addBond(new Bond(nAtoms + atomIndex1 - 1, nAtoms + atomIndex2 - 1,
order));
}
}
void readResInfo(BufferedReader reader, int resCount) throws Exception {
+ // free format, but no blank lines
for (int i = 0; i < resCount; ++i) {
reader.readLine();
//to be determined -- not implemented
@@ -115,13 +184,13 @@
void readCrystalInfo(BufferedReader reader) throws Exception {
// 4.1230 4.1230 4.1230 90.0000 90.0000 90.0000 221 1
- line=reader.readLine();
+ line = reader.readLine();
float[] notionalUnitcell = new float[6];
- ichNextParse=0;
+ ichNextParse = 0;
for (int i = 0; i < 6; i++)
notionalUnitcell[i] = parseFloat(line, ichNextParse);
atomSetCollection.setNotionalUnitcell(notionalUnitcell, logger);
- String spaceGroup = line.substring(ichNextParse,line.length()).trim();
- atomSetCollection.setAtomSetSpaceGroup(spaceGroup);
+ String spaceGroup = line.substring(ichNextParse, line.length()).trim();
+ atomSetCollection.setAtomSetSpaceGroup(spaceGroup);
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jmol-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-commits