OSDN Git Service

Features of Molecule#cell and Molecule#box are modified so that the handling of the...
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Mon, 18 Jun 2012 11:04:34 +0000 (11:04 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Mon, 18 Jun 2012 11:04:34 +0000 (11:04 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@222 a2be9bc6-48de-4e38-9406-05402d4bc13c

Documents/src/molby_rb/Molecule.html
MolLib/Molecule.c
MolLib/Ruby_bind/ruby_bind.c

index b0a90c0..de508ad 100644 (file)
@@ -628,6 +628,9 @@ the existing unit cell is cleared.
 This operation is undoable, in any of the above form.
 </p>
 <p>
+Note: if the sigma values of the cell parameters were already set by <a href="Molecule.html#M000236">Molecule#cell=</a>, those values are left untouched unless the cell itself is cleared.
+</p>
+<p>
 <i>See Also:</i> <a href="Molecule.html#M000238">Molecule#box</a>, <a href="Molecule.html#M000235">Molecule#cell</a>, <a href="Molecule.html#M000236">Molecule#cell=</a>
 </p>
 </div>
@@ -681,12 +684,12 @@ Calculate the dihedral angle defined by the four atoms. The result is in degree.
 <div id="method-M000235" class="method-detail">
 <a name="M000235"></a>
 <div class="method-heading">
-<span class="method-name">cell     &rarr; [a, b, c, alpha, beta, gamma]<br />
+<span class="method-name">cell     &rarr; [a, b, c, alpha, beta, gamma [, sig_a, sig_b, sig_c, sig_alpha, sig_beta, sig_gamma]]<br />
 </span>
 </div>
 <div class="method-description">
 <p>
-Returns the unit cell parameters. If a unit cell is not set, returns nil. Alpha/beta/gamma are in degree.
+Returns the unit cell parameters. If a unit cell is not set, returns nil. Alpha/beta/gamma are in degree. If the sigma value are present, the return value is an array of 12 floats instead of 6.
 </p>
 <p>
 <i>See Also:</i> <a href="Molecule.html#M000238">Molecule#box</a>, <a href="Molecule.html#M000239">Molecule#box=</a>, <a href="Molecule.html#M000236">Molecule#cell=</a>
@@ -697,14 +700,14 @@ Returns the unit cell parameters. If a unit cell is not set, returns nil. Alpha/
 <div id="method-M000236" class="method-detail">
 <a name="M000236"></a>
 <div class="method-heading">
-<span class="method-name">cell = [a, b, c, alpha, beta, gamma]<br />
-set_cell([a, b, c, alpha, beta, gamma], flag = nil)<br />
+<span class="method-name">cell = [a, b, c, alpha, beta, gamma [, sig_a, sig_b, sig_c, sig_alpha, sig_beta, sig_gamma]]<br />
+set_cell([a, b, c, alpha, beta, gamma [, sig_a, sig_b, sig_c, sig_alpha, sig_beta, sig_gamma]], flag = nil)<br />
 </span>
 </div>
 <div class="method-description">
 <p>
 Set the unit cell parameters. Alpha/beta/gamma are in degree. If the right-hand value (or the first argument) is nil, then clear the current unit cell. If the second argument is given as non-nil, then
-the coordinates are transformed so that the cartesian coordinates remain the same. This operation is undoable.
+the coordinates are transformed so that the cartesian coordinates remain the same. If the cell parameters are given as an array of 12 floats, then the second half of the array is to represent the sigma value (that are common in crystallographic data). This operation is undoable.
 </p>
 <p>
 <i>See Also:</i> <a href="Molecule.html#M000238">Molecule#box</a>, <a href="Molecule.html#M000239">Molecule#box=</a>, <a href="Molecule.html#M000235">Molecule#cell</a>
index 95ac532..d373442 100755 (executable)
@@ -967,8 +967,8 @@ MoleculeLoadMbsfFile(Molecule *mp, const char *fname, char *errbuf, int errbufsi
                                if (buf[0] == '\n')
                                        break;
                                /* ax ay az; bx by bz; cx cy cz; ox oy oz; fx fy fz [sigma; sa sb sc s_alpha s_beta s_gamma] */
-                               if (i < 5) {
-                                       if (sscanf(buf, "%lf %lf %lf %d", &dbuf[0], &dbuf[1], &dbuf[2]) < 3) {
+                               if (i < 4) {
+                                       if (sscanf(buf, "%lf %lf %lf", &dbuf[0], &dbuf[1], &dbuf[2]) < 3) {
                                                snprintf(errbuf, errbufsize, "line %d: bad periodic_box format", lineNumber);
                                                goto exit;
                                        }
@@ -984,9 +984,9 @@ MoleculeLoadMbsfFile(Molecule *mp, const char *fname, char *errbuf, int errbufsi
                                }
                                if (j == 4 && ibuf[3] != 0)
                                        has_sigma = 1;
-                               cbuf[0][0] = dbuf[0];
-                               cbuf[0][1] = dbuf[1];
-                               cbuf[0][2] = dbuf[2];
+                               cbuf[0][0] = ibuf[0];
+                               cbuf[0][1] = ibuf[1];
+                               cbuf[0][2] = ibuf[2];
                                MoleculeSetPeriodicBox(mp, vs, vs + 1, vs + 2, vs + 3, cbuf[0]);
                                if (has_sigma) {
                                        if (ReadLine(buf, sizeof buf, fp, &lineNumber) <= 0) {
@@ -8817,8 +8817,14 @@ MoleculeSetPeriodicBox(Molecule *mp, const Vector *ax, const Vector *ay, const V
        if (MoleculeCalculateCellFromAxes(&b, 1) < 0)
                return -1;
        __MoleculeLock(mp);
-       if (mp->cell != NULL)
+       if (mp->cell != NULL) {
+               if (mp->cell->has_sigma) {
+                       /*  Keep the sigma  */
+                       b.has_sigma = 1;
+                       memmove(b.cellsigma, mp->cell->cellsigma, sizeof(mp->cell->cellsigma));
+               }
                free(mp->cell);
+       }
        mp->cell = (XtalCell *)calloc(sizeof(XtalCell), 1);
        if (mp->cell != NULL) {
                memmove(mp->cell, &b, sizeof(XtalCell));
index 6f73404..b1af106 100644 (file)
@@ -5458,7 +5458,7 @@ s_Molecule_EachAtom(int argc, VALUE *argv, VALUE self)
 
 /*
  *  call-seq:
- *     cell     -> [a, b, c, alpha, beta, gamma]
+ *     cell     -> [a, b, c, alpha, beta, gamma [, sig_a, sig_b, sig_c, sig_alpha, sig_beta, sig_gamma]]
  *
  *  Returns the unit cell parameters. If cell is not set, returns nil.
  */
@@ -5474,42 +5474,48 @@ s_Molecule_Cell(VALUE self)
        val = rb_ary_new2(6);
        for (i = 0; i < 6; i++)
                rb_ary_push(val, rb_float_new(mol->cell->cell[i]));
+       if (mol->cell->has_sigma) {
+               for (i = 0; i < 6; i++) {
+                       rb_ary_push(val, rb_float_new(mol->cell->cellsigma[i]));
+               }
+       }
        return val;
 }
 
 /*
  *  call-seq:
- *     cell = [a, b, c, alpha, beta, gamma]
- *     set_cell([a, b, c, alpha, beta, gamma], flag = nil, sigma = nil)
+ *     cell = [a, b, c, alpha, beta, gamma [, sig_a, sig_b, sig_c, sig_alpha, sig_beta, sig_gamma]]
+ *     set_cell([a, b, c, alpha, beta, gamma[, sig_a, sig_b, sig_c, sig_alpha, sig_beta, sig_gamma]], flag = nil)
  *
- *  Set the unit cell parameters. If the cell value is nil, then clear the current cell. 
+ *  Set the unit cell parameters. If the cell value is nil, then clear the current cell.
+    If the given argument has 12 members, then the second half of the parameters represents the sigma values.
     This operation is undoable. If the second argument is given as non-nil, then 
        the coordinates are transformed so that the cartesian coordinates remain the same.
-    If the third argument is given, then standard deviations of the cell is also set.
  */
 static VALUE
 s_Molecule_SetCell(int argc, VALUE *argv, VALUE self)
 {
     Molecule *mol;
-       VALUE val, fval, sval;
-       int i, flag;
+       VALUE val, fval;
+       int i, flag, n;
        double d[12];
     Data_Get_Struct(self, Molecule, mol);
-       rb_scan_args(argc, argv, "12", &val, &fval, &sval);
+       rb_scan_args(argc, argv, "11", &val, &fval);
        flag = RTEST(fval);
        if (val == Qnil) {
                MolActionCreateAndPerform(mol, gMolActionSetCell, 0, d, flag);
        //      MoleculeSetCell(mol, 1, 1, 1, 90, 90, 90);
                return Qnil;
        }
-       for (i = 0; i < 6; i++)
-               d[i] = NUM2DBL(rb_Float(Ruby_ObjectAtIndex(val, i)));
-       if (sval != Qnil) {
-               for (i = 6; i < 11; i++)
-                       d[i] = NUM2DBL(rb_Float(Ruby_ObjectAtIndex(sval, i - 6)));
-       }
-       MolActionCreateAndPerform(mol, gMolActionSetCell, i, d, flag);
-//     MoleculeSetCell(mol, d[0], d[1], d[2], d[3], d[4], d[5]);
+       val = rb_ary_to_ary(val);
+       if (RARRAY_LEN(val) >= 12) {
+               n = 12;
+       } else if (RARRAY_LEN(val) >= 6) {
+               n = 6;
+       } else rb_raise(rb_eMolbyError, "too few members for cell parameters (6 or 12 required)");
+       for (i = 0; i < n; i++)
+               d[i] = NUM2DBL(rb_Float((RARRAY_PTR(val))[i]));
+       MolActionCreateAndPerform(mol, gMolActionSetCell, n, d, flag);
        return val;
 }
 
@@ -5569,6 +5575,7 @@ s_Molecule_Box(VALUE self)
     periodic along the axis.
     In the second form, an isotropic box with cell-length d is set.
     In the third form, the existing box is cleared.
+    Note: the sigma of the cell parameters is not cleared unless the periodic box itself is cleared.
  */
 static VALUE
 s_Molecule_SetBox(int argc, VALUE *argv, VALUE self)