Revision: 20972
          http://sourceforge.net/p/jmol/code/20972
Author:   hansonr
Date:     2016-03-03 22:49:45 +0000 (Thu, 03 Mar 2016)
Log Message:
-----------
Jmol.___JmolVersion="14.4.3_2016.03.03b"

bug fix: CIF reader _atom_site_cartn_x incompatible with _geom_bond
 -- this fix now allows Jmol to read very simple CIF files that are equivalent 
to unlimited-atom MOL files
 -- _ccdc_geom_bond_type is not required, defaulting to S
 -- _ccdc_geom_bond_types include S, D, T, Q (quadruple), and A (aromatic) 
         
        data_icosahedron
        loop_
        _atom_site_label
        _atom_site_Cartn_x
        _atom_site_Cartn_y
        _atom_site_Cartn_z
        C01  0.0000000000  0.0000000000  9.5105651630
        C02  8.5065080835  0.0000000000  4.2532540418
        C03  2.6286555606  8.0901699437  4.2532540418
        C04 -6.8819096024  5.0000000000  4.2532540418
        C05 -6.8819096024 -5.0000000000  4.2532540418
        C06  2.6286555606 -8.0901699437  4.2532540418
        C07  6.8819096024  5.0000000000 -4.2532540418
        C08 -2.6286555606  8.0901699437 -4.2532540418
        C09 -8.5065080835  0.0000000000 -4.2532540418
        C10 -2.6286555606 -8.0901699437 -4.2532540418
        C11  6.8819096024 -5.0000000000 -4.2532540418
        C12  0.0000000000  0.0000000000 -9.5105651630
        loop_
        _geom_bond_atom_site_label_1
        _geom_bond_atom_site_label_2
        _ccdc_geom_bond_type
        C01 C02 S
        C01 C03 S
        C01 C04 S
        C01 C05 S
        C01 C06 S
        C02 C03 S
        C03 C04 S
        C04 C05 S
        C05 C06 S
        ...etc... 
         

Modified Paths:
--------------
    branches/v14_4/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java
    trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java

Modified: branches/v14_4/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java
===================================================================
--- branches/v14_4/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java 
2016-03-03 03:41:27 UTC (rev 20971)
+++ branches/v14_4/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java 
2016-03-03 22:49:45 UTC (rev 20972)
@@ -1572,7 +1572,7 @@
       // this 5-model file can be read using one model at a time: load 
"c2cc34714h.txt" 3
       // but it is far from perfect, and still the best way is load 
"c2cc34714h.txt" 3 packed
       bondCount++;
-      bondTypes.addLast(new Object[] { name1, name2, Float.valueOf(distance),
+     bondTypes.addLast(new Object[] { name1, name2, Float.valueOf(distance),
           Float.valueOf(dx), Integer.valueOf(order) });
     }
     if (bondCount > 0) {
@@ -1626,7 +1626,7 @@
         bsSets[ipt] = new BS();
       bsSets[ipt].set(i - firstAtom);
     }
-
+    
     // if molecular, we need atom connection lists and radii
 
     if (isMolecular) {
@@ -1661,7 +1661,7 @@
       // main loop continues until no new atoms are found
     }
 
-    if (isMolecular) {
+    if (isMolecular && iHaveFractionalCoordinates) {
 
       // Set bsAtoms to control which atoms and 
       // bonds are delivered by the iterators.
@@ -1706,6 +1706,12 @@
     bsExclude = null;
   }
 
+  private void fixAtomForBonding(P3 pt, int i) {
+    pt = (pt == null ? atoms[i] : P3.newP(atoms[i]));
+    if (iHaveFractionalCoordinates)
+      symmetry.toCartesian(pt, true);
+  }
+
   /**
    * Use the site bitset to check for atoms that are within +/-dx Angstroms of
    * the specified distances in GEOM_BOND where dx is determined by the
@@ -1737,12 +1743,15 @@
       for (int j = bs1.nextSetBit(0); j >= 0; j = bs1.nextSetBit(j + 1))
         for (int k = bs2.nextSetBit(0); k >= 0; k = bs2.nextSetBit(k + 1)) {
           if ((!isMolecular || !bsConnected[j + firstAtom].get(k))
-              && symmetry.checkDistance(atoms[j + firstAtom], atoms[k
-                  + firstAtom], distance, dx, 0, 0, 0, ptOffset))
+              && checkBondDistance(atoms[j + firstAtom], atoms[k + firstAtom], 
distance, dx))
             addNewBond(j + firstAtom, k + firstAtom, order);
         }
     }
+    
+    if (!iHaveFractionalCoordinates)
+      return false;
 
+    
     // do a quick check for H-X bonds if we have GEOM_BOND
 
     if (bondTypes.size() > 0)
@@ -1754,8 +1763,7 @@
                 && atoms[k].elementNumber != 1
                 && (!checkAltLoc || atoms[k].altLoc == '\0' || atoms[k].altLoc 
== atoms[i].altLoc)) {
               if (!bsConnected[i].get(k)
-                  && symmetry.checkDistance(atoms[i], atoms[k], 1.1f, 0, 0, 0,
-                      0, ptOffset))
+                  && checkBondDistance(atoms[i], atoms[k], 1.1f, 0))
                 addNewBond(i, k, 1);
             }
         }
@@ -1793,16 +1801,14 @@
             for (int k = bsBranch.nextSetBit(0); k >= 0; k = bsBranch
                 .nextSetBit(k + 1)) {
               atoms[k].add(ptOffset);
-              cart1.setT(atoms[k]);
-              symmetry.toCartesian(cart1, true);
+              fixAtomForBonding(cart1, k);
               BS bs = bsSets[asc.getAtomIndex(atoms[k].atomName) - firstAtom];
               if (bs != null)
                 for (int ii = bs.nextSetBit(0); ii >= 0; ii = bs
                     .nextSetBit(ii + 1)) {
                   if (ii + firstAtom == k)
                     continue;
-                  cart2.setT(atoms[ii + firstAtom]);
-                  symmetry.toCartesian(cart2, true);
+                  fixAtomForBonding(cart2, ii + firstAtom);
                   if (cart2.distance(cart1) < 0.1f) {
                     bsExclude.set(k);
                     break;
@@ -1815,6 +1821,13 @@
     return false;
   }
 
+  private boolean checkBondDistance(Atom a, Atom b, float distance, float dx) {
+    if (iHaveFractionalCoordinates)
+      return  symmetry.checkDistance(a, b, distance, dx, 0, 0, 0, ptOffset);
+    float d = a.distance(b);
+    return (dx > 0 ? Math.abs(d - distance) <= dx : d <= distance && d > 
0.1f); // same as in Symmetry
+  }
+
   /**
    * add the bond and mark it for molecular processing
    * 

Modified: trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java  2016-03-03 
03:41:27 UTC (rev 20971)
+++ trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java  2016-03-03 
22:49:45 UTC (rev 20972)
@@ -1539,11 +1539,20 @@
       if (asc.getAtomIndex(name1 = getField(GEOM_BOND_ATOM_SITE_LABEL_1)) < 0
           || asc.getAtomIndex(name2 = getField(GEOM_BOND_ATOM_SITE_LABEL_2)) < 
0)
         continue;
+      int order = getBondOrder(getField(CCDC_GEOM_BOND_TYPE));
       float dx = 0;
       String sdist = getField(GEOM_BOND_DISTANCE);
       float distance = parseFloatStr(sdist);
-      if (distance == 0 || Float.isNaN(distance))
+      if (distance == 0 || Float.isNaN(distance)) {
+        if (!iHaveFractionalCoordinates) {
+          // maybe this is a simple Cartesian file with coordinates and bonds
+          Atom a = asc.getAtomFromName(name1);
+          Atom b = asc.getAtomFromName(name2);
+          if (a != null && b != null)
+            asc.addNewBondWithOrder(a.index, b.index, order);
+        }
         continue;
+      }
       int pt = sdist.indexOf('(');
       if (pt >= 0) {
         char[] data = sdist.toCharArray();
@@ -1564,7 +1573,6 @@
       } else {
         dx = 0.015f;
       }
-      int order = getBondOrder(getField(CCDC_GEOM_BOND_TYPE));
       // This field is from Materials Studio. See supplemental material for
       // http://pubs.rsc.org/en/Content/ArticleLanding/2012/CC/c2cc34714h
       // http://www.rsc.org/suppdata/cc/c2/c2cc34714h/c2cc34714h.txt
@@ -1661,7 +1669,7 @@
       // main loop continues until no new atoms are found
     }
 
-    if (isMolecular) {
+    if (isMolecular && iHaveFractionalCoordinates) {
 
       // Set bsAtoms to control which atoms and 
       // bonds are delivered by the iterators.
@@ -1706,6 +1714,12 @@
     bsExclude = null;
   }
 
+  private void fixAtomForBonding(P3 pt, int i) {
+    pt = (pt == null ? atoms[i] : P3.newP(atoms[i]));
+    if (iHaveFractionalCoordinates)
+      symmetry.toCartesian(pt, true);
+  }
+
   /**
    * Use the site bitset to check for atoms that are within +/-dx Angstroms of
    * the specified distances in GEOM_BOND where dx is determined by the
@@ -1737,12 +1751,15 @@
       for (int j = bs1.nextSetBit(0); j >= 0; j = bs1.nextSetBit(j + 1))
         for (int k = bs2.nextSetBit(0); k >= 0; k = bs2.nextSetBit(k + 1)) {
           if ((!isMolecular || !bsConnected[j + firstAtom].get(k))
-              && symmetry.checkDistance(atoms[j + firstAtom], atoms[k
-                  + firstAtom], distance, dx, 0, 0, 0, ptOffset))
+              && checkBondDistance(atoms[j + firstAtom], atoms[k + firstAtom], 
distance, dx))
             addNewBond(j + firstAtom, k + firstAtom, order);
         }
     }
 
+    if (!iHaveFractionalCoordinates)
+      return false;
+
+    
     // do a quick check for H-X bonds if we have GEOM_BOND
 
     if (bondTypes.size() > 0)
@@ -1754,8 +1771,7 @@
                 && atoms[k].elementNumber != 1
                 && (!checkAltLoc || atoms[k].altLoc == '\0' || atoms[k].altLoc 
== atoms[i].altLoc)) {
               if (!bsConnected[i].get(k)
-                  && symmetry.checkDistance(atoms[i], atoms[k], 1.1f, 0, 0, 0,
-                      0, ptOffset))
+                  && checkBondDistance(atoms[i], atoms[k], 1.1f, 0))
                 addNewBond(i, k, 1);
             }
         }
@@ -1793,16 +1809,14 @@
             for (int k = bsBranch.nextSetBit(0); k >= 0; k = bsBranch
                 .nextSetBit(k + 1)) {
               atoms[k].add(ptOffset);
-              cart1.setT(atoms[k]);
-              symmetry.toCartesian(cart1, true);
+              fixAtomForBonding(cart1, k);
               BS bs = bsSets[asc.getAtomIndex(atoms[k].atomName) - firstAtom];
               if (bs != null)
                 for (int ii = bs.nextSetBit(0); ii >= 0; ii = bs
                     .nextSetBit(ii + 1)) {
                   if (ii + firstAtom == k)
                     continue;
-                  cart2.setT(atoms[ii + firstAtom]);
-                  symmetry.toCartesian(cart2, true);
+                  fixAtomForBonding(cart2, ii + firstAtom);
                   if (cart2.distance(cart1) < 0.1f) {
                     bsExclude.set(k);
                     break;
@@ -1815,6 +1829,13 @@
     return false;
   }
 
+  private boolean checkBondDistance(Atom a, Atom b, float distance, float dx) {
+    if (iHaveFractionalCoordinates)
+      return  symmetry.checkDistance(a, b, distance, dx, 0, 0, 0, ptOffset);
+    float d = a.distance(b);
+    return (dx > 0 ? Math.abs(d - distance) <= dx : d <= distance && d > 
0.1f); // same as in Symmetry
+  }
+
   /**
    * add the bond and mark it for molecular processing
    * 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to