Revision: 18612
          http://sourceforge.net/p/jmol/code/18612
Author:   hansonr
Date:     2013-08-21 22:41:14 +0000 (Wed, 21 Aug 2013)
Log Message:
-----------
Incommensurate modulation work up to subsystems. 

Modified Paths:
--------------
    trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java
    trunk/Jmol/src/org/jmol/adapter/readers/cif/ModulationReader.java
    trunk/Jmol/src/org/jmol/adapter/readers/xtal/JanaReader.java
    trunk/Jmol/src/org/jmol/api/SymmetryInterface.java
    trunk/Jmol/src/org/jmol/symmetry/SpaceGroup.java
    trunk/Jmol/src/org/jmol/symmetry/Symmetry.java
    trunk/Jmol/src/org/jmol/util/Matrix3f.java
    trunk/Jmol/src/org/jmol/util/Modulation.java
    trunk/Jmol/src/org/jmol/util/ModulationSet.java

Modified: trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java  2013-08-21 
14:46:32 UTC (rev 18611)
+++ trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java  2013-08-21 
22:41:14 UTC (rev 18612)
@@ -1036,7 +1036,7 @@
           break;
         case OCCUPANCY:
           float floatOccupancy = parseFloatStr(field);
-          if (Float.isNaN(floatOccupancy))
+          if (!Float.isNaN(floatOccupancy))
             atom.foccupancy = floatOccupancy;
           break;
         case B_ISO:

Modified: trunk/Jmol/src/org/jmol/adapter/readers/cif/ModulationReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/adapter/readers/cif/ModulationReader.java   
2013-08-21 14:46:32 UTC (rev 18611)
+++ trunk/Jmol/src/org/jmol/adapter/readers/cif/ModulationReader.java   
2013-08-21 22:41:14 UTC (rev 18612)
@@ -164,8 +164,10 @@
   }
   
   protected void finalizeModulation() {
-    if (incommensurate && !modVib)
-      addJmolScript("modulation on");
+    if (!incommensurate)
+      return;
+    if (!modVib)
+      addJmolScript("modulation on" + (haveOccupancy  ? ";display occupancy > 
0.5" : ""));
   }
 
   private String suffix;
@@ -173,8 +175,9 @@
     return htModulation.get(key + suffix);
   }
   
-  private P3[] q123;
+  private Matrix3f q123;
   private double[] qlen;
+  private boolean haveOccupancy;
   
   private void setModulationForStructure(int iModel) {
     suffix = "@" + iModel;
@@ -182,19 +185,19 @@
     if (htModulation.containsKey("X_" + suffix))
       return;
     htModulation.put("X_" +suffix, new P3());
-    q123 = new P3[3];
+    q123 = new Matrix3f();
     qlen = new double[modDim];
     for (int i = 0; i < modDim; i++) {
-      q123[i] = getMod("W_" + (i + 1));
-      if (q123[i] == null) {
+      P3 pt = getMod("W_" + (i + 1));
+      if (pt == null) {
         Logger.info("Not enough cell wave vectors for d=" + modDim);
         return;
       }
-      qlen[i] = q123[i].length();
+      if (i == 0)
+        q1 = P3.newP(pt);
+      q123.setRowV(i, pt);
+      qlen[i] = pt.length();
     }
-    for (int i = modDim; i < 3; i++)
-      q123[i] = new P3();
-    q1 = q123[0];
     q1Norm = V3.new3(q1.x == 0 ? 0 : 1, q1.y == 0 ? 0 : 1, q1.z == 0 ? 0 : 1);
     P3 qlist100 = P3.new3(1, 0, 0);
     P3 pt;    
@@ -206,8 +209,7 @@
       pt = e.getValue();
       switch (key.charAt(0)) {
       case 'O':
-          if (!modVib && bsAtoms == null)
-            bsAtoms = atomSetCollection.bsAtoms = BSUtil.newBitSet2(0, n);
+        haveOccupancy = true;
         //$FALL-THROUGH$
       case 'D':
         // fix modulus/phase option only for non-special modulations;
@@ -356,25 +358,23 @@
       Logger.debug("setModulation iop = " + iop + " "
           + symmetry.getSpaceGroupXyz(iop, false) + " " + a.bsSymmetry);
     }
-
+    Matrix4f q123w = Matrix4f.newMV(q123, new V3());
+    setSubsystemMatrix(a.atomName, q123w);
     ModulationSet ms = new ModulationSet(a.index + " " + a.atomName, 
-        P3.newP(a), a.foccupancy / 10000f, modDim, list, gammaE, gammaIS, 
q123, qlen);
+        P3.newP(a), a.foccupancy, modDim, list, gammaE, gammaIS, q123w, qlen);
     a.vib = ms;
     ms.calculate();
-    float occ = ms.vOcc;
-    if (!Float.isNaN(occ)) {
-      if (modVib && !Float.isNaN(ms.vOcc0)) {
-        a.foccupancy = Math.min(1, Math.max(0, ms.vOcc0 + occ));
-        if (a.foccupancy  < 0)
-          a.foccupancy = 0;
-        
-      } else if (occ < 0.5f) {
-        a.foccupancy = 0;
-        if (bsAtoms != null)
-          bsAtoms.clear(a.index);
-      } else if (occ >= 0.5f) {
-        a.foccupancy = 1;
-      }
+    if (!Float.isNaN(ms.vOcc)) {
+      a.foccupancy = Math.min(1, Math.max(0, ms.vOcc0 + ms.vOcc));
+//      if (!modVib) {
+//        if (occ < 0.5f) {
+//          a.foccupancy = 0;
+//          if (bsAtoms != null)
+//            bsAtoms.clear(a.index);
+//        } else if (occ >= 0.5f) {
+//          a.foccupancy = 1;
+//        }
+//      } 
     }
     if (ms.htUij != null) {
       // Uiso or Uij. We add the displacements, create the tensor, then rotate 
it, 
@@ -416,6 +416,16 @@
     //System.out.println("a.vib(xyz)=" + a.vib);
   }
   
+  private void setSubsystemMatrix(String atomName, Matrix4f q123w) {
+    Object o;
+    if (true || htSubsystems == null || (o = htSubsystems.get(";" + atomName)) 
== null)
+      return;
+// not sure what to do yet.
+    String subcode = (String) o;
+    Matrix4f wmatrix = (Matrix4f) htSubsystems.get(subcode);
+    q123w.mulM4(wmatrix);
+  }
+
   protected void addSubsystem(String code, Matrix4f m4, String atomName) {
     if (htSubsystems == null)
       htSubsystems = new Hashtable<String, Object>();

Modified: trunk/Jmol/src/org/jmol/adapter/readers/xtal/JanaReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/adapter/readers/xtal/JanaReader.java        
2013-08-21 14:46:32 UTC (rev 18611)
+++ trunk/Jmol/src/org/jmol/adapter/readers/xtal/JanaReader.java        
2013-08-21 22:41:14 UTC (rev 18612)
@@ -24,6 +24,8 @@
 package org.jmol.adapter.readers.xtal;
 
 import java.io.BufferedReader;
+import java.util.Hashtable;
+import java.util.Map;
 
 
 import org.jmol.adapter.readers.cif.ModulationReader;
@@ -32,6 +34,7 @@
 import org.jmol.util.BS;
 import org.jmol.util.JmolList;
 import org.jmol.util.Logger;
+import org.jmol.util.Matrix4f;
 import org.jmol.util.P3;
 import org.jmol.util.TextFormat;
 
@@ -43,17 +46,17 @@
 public class JanaReader extends ModulationReader {
 
   private JmolList<float[]> lattvecs;
+  private int thisSub;
   
   @Override
   public void initializeReader() throws Exception {
       setFractionalCoordinates(true);
       initializeModulation();
       atomSetCollection.newAtomSet();
-      forcePacked = true; // need site occupancies anyway
   }
   
-  final static String records = "tit  cell ndim qi   lat  sym  spg  end";
-  //                             0    5    10   15   20   25   30   35
+  final static String records = "tit  cell ndim qi   lat  sym  spg  end  wma";
+  //                             0    5    10   15   20   25   30   35   40
   final static int TITLE = 0;
   final static int CELL  = 5;
   final static int NDIM  = 10;
@@ -62,6 +65,7 @@
   final static int SYM   = 25;
   final static int SPG   = 30;
   final static int END   = 35;
+  final static int WMATRIX = 40;
   
 //  Version Jana2006
 //  title
@@ -114,6 +118,18 @@
       case END:
         continuing = false;
         break;
+      case WMATRIX:
+        Matrix4f m = new Matrix4f();
+        if (thisSub++ == 0) {
+          m.setIdentity();
+          addSubsystem("1", m, null);
+          thisSub++;
+          m = new Matrix4f();
+        }
+        float[] data = new float[16];
+        fillFloatArray(null, 0, data);
+        m.setA(data, 0);
+        addSubsystem("" + thisSub, m, null);
     }
     return true;
   }
@@ -229,16 +245,27 @@
         .getLigandModel(id, name, "_file", "----"));
     if (readM40Floats(r).startsWith("command"))
       readM40WaveVectors(r);
-    int nAtoms = (int) floats[0];
-    for (int i = 0; i < nAtoms; i++) {
-      while (readM40Floats(r).length() == 0 || line.charAt(0) == ' '
-          || line.charAt(0) == '-') {
+    BS newSub = getSubSystemList();
+    int iSub = (newSub == null ? 0 : 1);
+    int nAtoms = -1;
+    while (readM40Floats(r) != null) {
+      while (line != null && (line.length() == 0 || line.charAt(0) == ' '
+          || line.charAt(0) == '-')) {
+        readM40Floats(r);
       }
-
+      if (line == null)
+        break;
+      nAtoms++;
       Atom atom = new Atom();
       atom.atomName = line.substring(0, 9).trim();
+      Logger.info(line);
       if (!filterAtom(atom, 0))
         continue;
+      if (iSub > 0) {
+        if (newSub.get(nAtoms))
+          iSub++;
+        addSubsystem("" + iSub, null, atom.atomName);
+      }
       atom.foccupancy = floats[2];
       setAtomCoordXYZ(atom, floats[3], floats[4], floats[5]);
       atomSetCollection.addAtom(atom);
@@ -314,7 +341,8 @@
         } else {
           if (haveSpecialUij) {
             //TODO
-            Logger.error("JanaReader -- not interpreting SpecialUij flag: " + 
line);
+            Logger.error("JanaReader -- not interpreting SpecialUij flag: "
+                + line);
           } else {
             float[][] data = readM40FloatLines(2, 6, r);
             for (int k = 0, p = 0; k < 6; k++, p += 3)
@@ -328,6 +356,20 @@
     r.close();
   }
 
+  private BS getSubSystemList() {
+    if (htSubsystems == null)
+      return null;
+    BS bs = new BS();
+    String[] tokens = getTokens();
+    for (int i = 0, n = 0; i < tokens.length; i+= 2) {
+      int nAtoms = parseIntStr(tokens[i]);
+      if (nAtoms == 0)
+        break;
+      bs.set(n = n + nAtoms);
+    }
+    return bs;
+  }
+
   private void readM40WaveVectors(BufferedReader r) throws Exception {
     while (!readM40Floats(r).contains("end"))
       if (line.startsWith("wave")) {
@@ -382,7 +424,8 @@
   private float[] floats = new float[6];
   
   private String readM40Floats(BufferedReader r) throws Exception {
-    line = r.readLine();
+    if ((line = r.readLine()) == null || line.indexOf("-------") >= 0) 
+      return (line = null);
     if (Logger.debugging)
       Logger.debug(line);
     int ptLast = line.length() - 10;
@@ -405,15 +448,17 @@
    * M40 occupancies are divided by the site multiplicity
    */
   private void adjustM40Occupancies() {
-    int nOps = atomSetCollection.getSymmetry().getSpaceGroupOperationCount();
-    BS bsSite = new BS();
+    Map<String, Integer> htSiteMult = new Hashtable<String, Integer>();    
     Atom[] atoms = atomSetCollection.getAtoms();
     for (int i = atomSetCollection.getAtomCount(); --i >= 0;) {
       Atom a = atoms[i];
-      bsSite.clearAll();
-      bsSite.setBits(0, nOps);
-      bsSite.and(a.bsSymmetry);
-      a.foccupancy *= bsSite.cardinality();
+      Integer ii = htSiteMult.get(a.atomName);
+      if (ii == null) {
+        System.out.println(a.atomName);
+        htSiteMult.put(a.atomName, ii = 
Integer.valueOf(atomSetCollection.getSymmetry().getSiteMultiplicity(a)));
+        System.out.println(a.atomName + " " + ii + " " + a.bsSymmetry + " " + 
a.foccupancy);
+      }
+      a.foccupancy *= ii.intValue();
     }
   }
 }

Modified: trunk/Jmol/src/org/jmol/api/SymmetryInterface.java
===================================================================
--- trunk/Jmol/src/org/jmol/api/SymmetryInterface.java  2013-08-21 14:46:32 UTC 
(rev 18611)
+++ trunk/Jmol/src/org/jmol/api/SymmetryInterface.java  2013-08-21 22:41:14 UTC 
(rev 18612)
@@ -178,5 +178,7 @@
   public boolean hasLatticeCentering();
 
   public Matrix4f getOperationGammaIS(int iop);
+
+  public int getSiteMultiplicity(P3 a);
   
 }

Modified: trunk/Jmol/src/org/jmol/symmetry/SpaceGroup.java
===================================================================
--- trunk/Jmol/src/org/jmol/symmetry/SpaceGroup.java    2013-08-21 14:46:32 UTC 
(rev 18611)
+++ trunk/Jmol/src/org/jmol/symmetry/SpaceGroup.java    2013-08-21 22:41:14 UTC 
(rev 18612)
@@ -1401,7 +1401,29 @@
     }
   }
 
+  public int getSiteMultiplicity(P3 pt, UnitCell unitCell) {
+    int n = finalOperations.length;
+    JmolList<P3> pts = new JmolList<P3>();
+    for (int i = n; --i >= 0;) {
+      P3 pt1 = P3.newP(pt);
+      finalOperations[i].transform(pt1);
+      unitCell.unitize(pt1);
+      for (int j = pts.size(); --j >= 0;) {
+        P3 pt0 = pts.get(j);
+        if (pt1.distanceSquared(pt0) < 0.000001f) {
+          pt1 = null;
+          break;
+        }      
+      }
+      if (pt1 != null) {
+        //System.out.println(pt + " to " + pt1 + " by " + i + ": " + 
finalOperations[i].xyz);
+        pts.addLast(pt1);
+      }
+    }
+    return n / pts.size();
+  }
 
+
   /*  see http://cci.lbl.gov/sginfo/itvb_2001_table_a1427_hall_symbols.html
 
 intl#     H-M full       HM-abbr   HM-short  Hall

Modified: trunk/Jmol/src/org/jmol/symmetry/Symmetry.java
===================================================================
--- trunk/Jmol/src/org/jmol/symmetry/Symmetry.java      2013-08-21 14:46:32 UTC 
(rev 18611)
+++ trunk/Jmol/src/org/jmol/symmetry/Symmetry.java      2013-08-21 22:41:14 UTC 
(rev 18612)
@@ -653,7 +653,11 @@
     return spaceGroup.finalOperations[iop].gammaIS;
   }
 
+  public int getSiteMultiplicity(P3 pt) {
+    return spaceGroup.getSiteMultiplicity(pt,unitCell);
+  }
 
 
 
+
 }  

Modified: trunk/Jmol/src/org/jmol/util/Matrix3f.java
===================================================================
--- trunk/Jmol/src/org/jmol/util/Matrix3f.java  2013-08-21 14:46:32 UTC (rev 
18611)
+++ trunk/Jmol/src/org/jmol/util/Matrix3f.java  2013-08-21 22:41:14 UTC (rev 
18612)
@@ -279,7 +279,7 @@
    * @param v
    *        the replacement row
    */
-  public final void setRowV(int row, V3 v) {
+  public final void setRowV(int row, Tuple3f v) {
     if (row == 0) {
       m00 = v.x;
       m01 = v.y;

Modified: trunk/Jmol/src/org/jmol/util/Modulation.java
===================================================================
--- trunk/Jmol/src/org/jmol/util/Modulation.java        2013-08-21 14:46:32 UTC 
(rev 18611)
+++ trunk/Jmol/src/org/jmol/util/Modulation.java        2013-08-21 22:41:14 UTC 
(rev 18612)
@@ -154,7 +154,7 @@
 
       x -= Math.floor(x);
       ms.vOcc = (range(x) ? 1 : 0);
-      ms.vOcc0 = Float.NaN; // don't add this in
+      ms.vOcc0 = 0; // absolute
       //System.out.println("MOD " + ms.r + " " +  ms.delta + " " + ms.epsilon 
+ " " + ms.id + " " + ms.v + " l=" + left + " x=" + x4 + " r=" + right);
       return;
     case TYPE_DISP_SAWTOOTH:

Modified: trunk/Jmol/src/org/jmol/util/ModulationSet.java
===================================================================
--- trunk/Jmol/src/org/jmol/util/ModulationSet.java     2013-08-21 14:46:32 UTC 
(rev 18611)
+++ trunk/Jmol/src/org/jmol/util/ModulationSet.java     2013-08-21 22:41:14 UTC 
(rev 18612)
@@ -46,7 +46,8 @@
    */
 
   public ModulationSet(String id, P3 r, float vocc0, int modDim, 
-                       JmolList<Modulation> mods, Matrix3f gammaE, Matrix4f 
gammaIS, P3[] q123, double[] qlen) {
+                       JmolList<Modulation> mods, Matrix3f gammaE, 
+                       Matrix4f gammaIS, Matrix4f q123w, double[] qlen) {
     this.id = id;
     this.vOcc0 = vocc0;
     this.modDim = modDim;
@@ -61,11 +62,13 @@
     
     gammaIS.get(sI);
     gammaIinv.invert();
-    x456 = V3.new3(q123[0].dot(r), q123[1].dot(r), q123[2].dot(r));
+    x456 = V3.newV(r);
+    Matrix3f m = new Matrix3f();
+    q123w.transform(x456);
     x456.sub(sI);
     gammaIinv.transform(x456);
     if (Logger.debuggingHigh)
-      Logger.debug("MODSET create r=" + Escape.eP(r) + " q0=" + 
Escape.eP(q123[0]) 
+      Logger.debug("MODSET create r=" + Escape.eP(r)
         + " si=" + Escape.eP(sI) + " ginv=" + 
gammaIinv.toString().replace('\n',' ') + " x4=" + x456.x);
 
     // temporary only - only for d=1:

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


------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to