Revision: 5242
Author:   hansonr
Date:     2006-06-25 19:56:05 -0700 (Sun, 25 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/jmol/?rev=5242&view=rev

Log Message:
-----------
bob200603 adds very basic MOL2 (tripos SYBYL) file reader -- atoms, bonds, and 
unit cell info only

Modified Paths:
--------------
    branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Resolver.java

Added Paths:
-----------
    branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java
Added: branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java
===================================================================
--- branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java        
                        (rev 0)
+++ branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java        
2006-06-26 02:56:05 UTC (rev 5242)
@@ -0,0 +1,127 @@
+/* $RCSfile$
+ * $Author: hansonr $
+ * $Date: 2006-03-15 07:52:29 -0600 (Wed, 15 Mar 2006) $
+ * $Revision: 4614 $
+ *
+ * Copyright (C) 2003-2005  Miguel, Jmol Development, www.jmol.org
+ *
+ * Contact: [EMAIL PROTECTED]
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jmol.adapter.smarter;
+
+import java.io.BufferedReader;
+
+import org.jmol.api.JmolAdapter;
+
+/**
+ * A MINIMAL reader for TRIPOS mol2 files.
+ *<p>
+ * <a href='http://www.tripos.com/data/support/mol2.pdf '>
+ * http://www.tripos.com/data/support/mol2.pdf 
+ * </a>
+ *<p>
+ */
+class Mol2Reader extends AtomSetCollectionReader {
+
+  String line;
+
+  AtomSetCollection readAtomSetCollection(BufferedReader reader)
+      throws Exception {
+    atomSetCollection = new AtomSetCollection("mol2");
+    line = reader.readLine();
+    int atomCount = 0;
+    int bondCount = 0;
+    int resCount = 0;
+    while (line != null) {
+      if (line.equals("global")) {
+        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);
+      } else if (line.equals("@<TRIPOS>BOND")) {
+        readBonds(reader, bondCount);
+      } else if (line.equals("@<TRIPOS>SUBSTRUCTURE")) {
+        readResInfo(reader, resCount);
+      } else if (line.equals("@<TRIPOS>CRYSIN")) {
+        readCrystalInfo(reader);
+      }
+      line = reader.readLine();
+    }
+    return atomSetCollection;
+  }
+
+  void readAtoms(BufferedReader reader, int atomCount) throws Exception {
+    //     1 Cs       0.0000   4.1230   0.0000   Cs        1 RES1   0.0000
+    //          1         2         3         4         5         6
+    //012345678901234567890123456789012345678901234567890123456789012345678
+    for (int i = 0; i < atomCount; ++i) {
+      String line = reader.readLine();
+      String elementSymbol = line.substring(43, 45);
+      if (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();
+      atom.elementSymbol = elementSymbol;
+      atom.formalCharge = charge;
+      atom.x = x;
+      atom.y = y;
+      atom.z = z;
+    }
+  }
+
+  void readBonds(BufferedReader reader, int bondCount) throws Exception {
+    //     6     1    42    1
+    //          1         2         3         4         5         6
+    //012345678901234567890123456789012345678901234567890123456789012345678
+    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);
+      if (order == Integer.MIN_VALUE)
+        order = JmolAdapter.ORDER_AROMATIC;
+      atomSetCollection
+          .addBond(new Bond(atomIndex1 - 1, atomIndex2 - 1, order));
+    }
+  }
+
+  void readResInfo(BufferedReader reader, int resCount) throws Exception {
+    for (int i = 0; i < resCount; ++i) {
+      reader.readLine();
+      //to be determined -- not implemented
+    }
+  }
+
+  void readCrystalInfo(BufferedReader reader) throws Exception {
+    //    4.1230    4.1230    4.1230   90.0000   90.0000   90.0000   221     1
+    line=reader.readLine();
+    float[] notionalUnitcell = new float[6];
+    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); 
+  }
+}

Modified: branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Resolver.java
===================================================================
--- branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Resolver.java  
2006-06-25 15:54:35 UTC (rev 5241)
+++ branches/bob200603/Jmol/src/org/jmol/adapter/smarter/Resolver.java  
2006-06-26 02:56:05 UTC (rev 5242)
@@ -266,11 +266,14 @@
   final static String[] cubeRecords =
   {"JVXL"};
 
+  final static String[] mol2Records =
+  {"@<TRIPOS>"};
+
   final static String[][] fileStartsWithRecords =
-  { nwchemRecords, cubeRecords};
+  { nwchemRecords, cubeRecords, mol2Records};
 
   final static String[] fileStartsWithFormats =
-  { "NWChem", "Cube"};
+  { "NWChem", "Cube", "Mol2"};
 
   ////////////////////////////////////////////////////////////////
   // these test lines that startWith one of these strings


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

Reply via email to