From 6f0f2ef59fd7cd1c65b0db18081b664aee7e753a Mon Sep 17 00:00:00 2001 From: toshinagata1964 Date: Thu, 2 Aug 2012 07:46:07 +0000 Subject: [PATCH] Property table can now list the unit cell parameters. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@273 a2be9bc6-48de-4e38-9406-05402d4bc13c --- Documents/src/molby_rb/Molecule.html | 8 +-- MolLib/MainView.c | 102 ++++++++++++++++++++++++++++++++--- MolLib/MainView.h | 3 +- MolLib/MolAction.c | 31 ++++++++--- MolLib/Molecule.c | 55 ++++++++++++------- MolLib/Molecule.h | 2 +- MolLib/Ruby_bind/ruby_bind.c | 17 +++--- MolLib/Ruby_bind/ruby_md.c | 2 +- wxSources/MoleculeView.cpp | 2 +- 9 files changed, 174 insertions(+), 48 deletions(-) diff --git a/Documents/src/molby_rb/Molecule.html b/Documents/src/molby_rb/Molecule.html index 0719a54..2e06bb1 100644 --- a/Documents/src/molby_rb/Molecule.html +++ b/Documents/src/molby_rb/Molecule.html @@ -600,10 +600,10 @@ periodic along the axis. If no unit cell is defined, nil is returned.
-self.box = [avec, bvec, cvec, origin = [0, 0, 0], flags = [1, 1, 1]]
+self.box = [avec, bvec, cvec, origin = [0, 0, 0], flags = [1, 1, 1], convert_coord = nil]
self.box = [d, origin = [0, 0, 0]]
self.box = nil
-set_box(avec, bvec, cvec, origin = [0, 0, 0], flags = [1, 1, 1])
+set_box(avec, bvec, cvec, origin = [0, 0, 0], flags = [1, 1, 1], convert_coord = nil)
set_box(d, origin = [0, 0, 0])
set_box
@@ -615,7 +615,7 @@ bvec, and cvec can be either a Vector3D or a number. If it is a number, the x/y/z axis vector is multiplied with the given number and used as the cell axis vector. Flags, if present, is a 3-member array of Integers defining whether -the system is periodic along the axis. +the system is periodic along the axis. If convert_coord is true (neither nil nor false), the coordinates of atoms are converted so that the fractional cooordinates remain the same.

In the second form, an isotropic box with cell-length d is set. @@ -707,7 +707,7 @@ set_cell([a, b, c, alpha, beta, gamma [, sig_a, sig_b, sig_c, sig_alpha, sig_bet

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. 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. +the coordinates are transformed so that the fractional 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.

See Also: Molecule#box, Molecule#box=, Molecule#cell diff --git a/MolLib/MainView.c b/MolLib/MainView.c index 9625081..7ecf574 100755 --- a/MolLib/MainView.c +++ b/MolLib/MainView.c @@ -249,7 +249,8 @@ MainView_refreshCachedInfo(MainView *mview) j++; } } - } else if (mview->tableIndex == kMainViewParameterTableIndex) { /* Parameter infos */ + } else if (mview->tableIndex == kMainViewParameterTableIndex || /* Parameter infos */ + mview->tableIndex == kMainViewUnitCellTableIndex) { /* Unit cell infos */ /* Do nothing (tableCache will not be used) */ } else if (mview->tableIndex == kMainViewMOTableIndex) { /* MO infos */ /* Really no need to cache info, but create it anyway to simplify code */ @@ -3081,14 +3082,17 @@ static ColumnInfoRecord sImproperColumns[] = { static ColumnInfoRecord sParameterColumns[] = { {"class", 5, 0}, {"type", 9, 0}, {"", 6, 0}, {"", 6, 0}, {"", 6, 0}, {"", 6, 0}, {"", 6, 0}, {"", 6, 0}, {"src", 8, 0}, {"comment", 25, 0}, {NULL} }; +static ColumnInfoRecord sUnitCellColumns[] = { +{"name", 6, 0}, {"values", 9, 1}, {"", 9, 1}, {"", 9, 1}, {NULL} +}; static ColumnInfoRecord sMOEnergyColumns[] = { {"MO", 5, 0}, {"alpha energy", 12, 0}, {"beta energy", 12, 0}, {NULL} }; static ColumnInfoRecord *sColumnInfo[] = { -sAtomColumns, sBondColumns, sAngleColumns, sDihedralColumns, sImproperColumns, sParameterColumns, sMOEnergyColumns +sAtomColumns, sBondColumns, sAngleColumns, sDihedralColumns, sImproperColumns, sParameterColumns, sUnitCellColumns, sMOEnergyColumns }; static char *sTableTitles[] = { - "atom", "bond", "angle", "dihedral", "improper", "parameter", "MO energy" + "atom", "bond", "angle", "dihedral", "improper", "parameter", "unit cell", "MO energy" }; void @@ -3169,6 +3173,8 @@ MainView_numberOfRowsInTable(MainView *mview) return 0; if (mview->tableIndex == kMainViewParameterTableIndex) return ParameterTableNumberOfRows(mview->mol->par); + if (mview->tableIndex == kMainViewUnitCellTableIndex) + return 13; /* a, b, c, alpha, beta, gamma, a_valid, b_valid, c_valid, av, bv, cv, ov */ if (mview->tableCache == NULL) MainView_refreshCachedInfo(mview); return IntGroupGetCount(mview->tableCache); @@ -3179,7 +3185,7 @@ MainView_indexToTableRow(MainView *mview, int idx) { if (mview == NULL) return -1; - if (mview->tableIndex == kMainViewParameterTableIndex) + if (mview->tableIndex == kMainViewParameterTableIndex || mview->tableIndex == kMainViewUnitCellTableIndex) return -1; /* Not supported yet */ return IntGroupLookupPoint(mview->tableCache, idx); } @@ -3189,7 +3195,7 @@ MainView_tableRowToIndex(MainView *mview, int row) { if (mview == NULL) return -1; - if (mview->tableIndex == kMainViewParameterTableIndex) + if (mview->tableIndex == kMainViewParameterTableIndex || mview->tableIndex == kMainViewUnitCellTableIndex) return -1; /* Not supported yet */ return IntGroupGetNthPoint(mview->tableCache, row); } @@ -3365,6 +3371,39 @@ MainView_valueForTable(MainView *mview, int column, int row, char *buf, int bufs } default: buf[0] = 0; break; } + } else if (mview->tableIndex == kMainViewUnitCellTableIndex) { /* Unit cell info */ + buf[0] = 0; + if (mview->mol->cell != NULL) { + static const char *unitCellRowTitles[] = {"a", "b", "c", "alpha", "beta", "gamma", "a_valid", "b_valid", "c_valid", "a_vec", "b_vec", "c_vec", "origin"}; + if (column == 0) + snprintf(buf, bufsize, "%s", unitCellRowTitles[row]); + else { + switch(row) { + case 0: case 1: case 2: + if (column == 1) + snprintf(buf, bufsize, "%.5f", mview->mol->cell->cell[row]); + else if (column == 2 && mview->mol->cell->has_sigma) + snprintf(buf, bufsize, "%.5f", mview->mol->cell->cellsigma[row]); + break; + case 3: case 4: case 5: + if (column == 1) + snprintf(buf, bufsize, "%.4f", mview->mol->cell->cell[row]); + else if (column == 2 && mview->mol->cell->has_sigma) + snprintf(buf, bufsize, "%.4f", mview->mol->cell->cellsigma[row]); + break; + case 6: case 7: case 8: + if (column == 1) + snprintf(buf, bufsize, "%d", (int)mview->mol->cell->flags[row - 6]); + break; + case 9: case 10: case 11: case 12: { + Vector *vp = (row == 12 ? &mview->mol->cell->origin : &mview->mol->cell->axes[row - 9]); + Double dval = (column == 1 ? vp->x : (column == 2 ? vp->y : vp->z)); + snprintf(buf, bufsize, "%.5f", dval); + break; + } + } + } + } } else if (mview->tableIndex == kMainViewMOTableIndex) { /* MO energy */ BasisSet *bset = mview->mol->bset; idx = row; @@ -3502,7 +3541,7 @@ MainView_setSelectionFromTable(MainView *mview) IntGroup *ig, *sel; if (mview == NULL || mview->mol == NULL) return; - if (mview->tableIndex == kMainViewMOTableIndex || mview->tableIndex == kMainViewParameterTableIndex) + if (mview->tableIndex >= kMainViewParameterTableIndex) return; /* Do nothing */ ig = MainViewCallback_getTableSelection(mview); sel = IntGroupNew(); @@ -3636,6 +3675,50 @@ MainView_setValueForTable(MainView *mview, int column, int row, const char *buf) MolActionCreateAndPerform(mol, SCRIPT_ACTION("iss"), "set_atom_attr", idx, key, buf); } else if (mview->tableIndex == kMainViewParameterTableIndex) { /* Parameters */ sMainView_ParameterTableSetItemText(mview->mol, column, row, buf); + } else if (mview->tableIndex == kMainViewUnitCellTableIndex) { /* Unit cell */ + Double cellPars[12], dval; + char flags[3]; + int n1; + Vector vecs[4]; + if (mol->cell == NULL) { + /* Create a cell */ + static const Double sCellPars[] = {1, 1, 1, 90, 90, 90}; + MolActionCreateAndPerform(mol, gMolActionSetCell, 6, sCellPars, 0); + } + if (row >= 0 && row < 6) { + n1 = 6; + memmove(cellPars, mol->cell->cell, sizeof(Double) * 6); + if (mol->cell->has_sigma) + memmove(cellPars + 6, mol->cell->cellsigma, sizeof(Double) * 6); + else memset(cellPars + 6, 0, sizeof(Double) * 6); + dval = strtod(buf, NULL); + if (column == 1) { + if (dval == 0.0) + return; + cellPars[row] = dval; + } else { + n1 = 12; + cellPars[row + 6] = dval; + } + MolActionCreateAndPerform(mol, gMolActionSetCell, n1, cellPars, 0); + } else { + memmove(vecs, mol->cell->axes, sizeof(Vector) * 3); + vecs[3] = mol->cell->origin; + memmove(flags, mol->cell->flags, 3); + if (row >= 6 && row < 9) + flags[row - 6] = strtol(buf, NULL, 0); + else { + Vector *vp = vecs + (row - 9); + dval = strtod(buf, NULL); + if (column == 1) + vp->x = dval; + else if (column == 2) + vp->y = dval; + else vp->z = dval; + } + MolActionCreateAndPerform(mol, gMolActionSetBox, vecs, vecs + 1, vecs + 2, vecs + 3, (flags[0] != 0) * 4 + (flags[1] != 0) * 2 + (flags[2] != 0), 0); + } + } } @@ -3648,6 +3731,13 @@ MainView_isTableItemEditable(MainView *mview, int column, int row) return 0; if (mview->tableIndex == kMainViewParameterTableIndex) return ParameterTableIsItemEditable(mview->mol->par, column, row); + if (mview->tableIndex == kMainViewUnitCellTableIndex) { + if ((row >= 0 && row < 6 && column >= 1 && column <= 3) || + (row >= 6 && row < 9 && column == 1) || + (row >= 9 && row < 13 && column >= 1 && column <= 3)) + return 1; + else return 0; + } if (mview->tableIndex >= 0 && mview->tableIndex < sizeof(sColumnInfo) / sizeof(sColumnInfo[0])) return sColumnInfo[mview->tableIndex][column].editable != 0; else return 0; diff --git a/MolLib/MainView.h b/MolLib/MainView.h index 2ce2502..242d934 100755 --- a/MolLib/MainView.h +++ b/MolLib/MainView.h @@ -72,7 +72,8 @@ enum { kMainViewDihedralTableIndex = 3, kMainViewImproperTableIndex = 4, kMainViewParameterTableIndex = 5, - kMainViewMOTableIndex = 6 + kMainViewUnitCellTableIndex = 6, + kMainViewMOTableIndex = 7 }; enum { diff --git a/MolLib/MolAction.c b/MolLib/MolAction.c index 9f28894..e3efba9 100644 --- a/MolLib/MolAction.c +++ b/MolLib/MolAction.c @@ -56,7 +56,7 @@ const char *gMolActionExpandBySymmetry = "expandSym:Giiii;I"; const char *gMolActionDeleteSymmetryOperation = "deleteSymop"; const char *gMolActionAddSymmetryOperation = "addSymop:t"; const char *gMolActionSetCell = "setCell:Di"; -const char *gMolActionSetBox = "setBox:vvvvi"; +const char *gMolActionSetBox = "setBox:vvvvii"; const char *gMolActionClearBox = "clearBox"; const char *gMolActionSetBoxForFrames = "setBoxForFrames:V"; const char *gMolActionSetCellFlexibility = "setCellFlexibility:i"; @@ -1308,6 +1308,8 @@ static int s_MolActionSetCell(Molecule *mol, MolAction *action, MolAction **actp) { double *dp, d[12]; + Vector vecs[4]; + Int flags; Int convertCoord, n1, n2; if (mol->cell == NULL) { d[0] = 0.0; @@ -1319,6 +1321,9 @@ s_MolActionSetCell(Molecule *mol, MolAction *action, MolAction **actp) for (n1 = 6; n1 < 12; n1++) d[n1] = mol->cell->cellsigma[n1 - 6]; } + memmove(vecs, mol->cell->axes, sizeof(Vector) * 3); + vecs[3] = mol->cell->origin; + flags = (mol->cell->flags[0] != 0) * 4 + (mol->cell->flags[1] != 0) * 2 + (mol->cell->flags[2] != 0); } convertCoord = action->args[1].u.ival; dp = action->args[0].u.arval.ptr; @@ -1333,7 +1338,18 @@ s_MolActionSetCell(Molecule *mol, MolAction *action, MolAction **actp) mol->cell->cellsigma[n2 - 6] = dp[n2]; } else mol->cell->has_sigma = 0; } - *actp = MolActionNew(gMolActionSetCell, n1, (n1 == 0 ? NULL : d), convertCoord); + if (n1 == 0) + *actp = MolActionNew(gMolActionClearBox); + else { + *actp = MolActionNew(gMolActionSetBox, &vecs[0], &vecs[1], &vecs[2], &vecs[3], flags, convertCoord); + if (n1 > 6) { + /* Two undo actions are needed: first is for restore the cell vectors, and second is for restore the sigmas */ + MolAction *act2; + act2 = MolActionNew(gMolActionSetCell, n1, d, 0); + MolActionCallback_registerUndo(mol, act2); + MolActionRelease(act2); + } + } return 0; } @@ -1346,17 +1362,18 @@ s_MolActionSetBox(Molecule *mol, MolAction *action, MolAction **actp) if (mol->cell == NULL) return 0; /* Do nothing */ n1 = ((mol->cell->flags[0] != 0) * 4 + (mol->cell->flags[1] != 0) * 2 + (mol->cell->flags[2] != 0)); - *actp = MolActionNew(gMolActionSetBox, &(mol->cell->axes[0]), &(mol->cell->axes[1]), &(mol->cell->axes[2]), &(mol->cell->origin), n1); - MoleculeSetPeriodicBox(mol, NULL, NULL, NULL, NULL, NULL); + *actp = MolActionNew(gMolActionSetBox, &(mol->cell->axes[0]), &(mol->cell->axes[1]), &(mol->cell->axes[2]), &(mol->cell->origin), n1, 0); + MoleculeSetPeriodicBox(mol, NULL, NULL, NULL, NULL, NULL, 0); } else { /* Set box */ Vector v[4]; char flags[3]; + int convertCoordinates = action->args[5].u.ival; if (mol->cell == NULL) *actp = MolActionNew(gMolActionClearBox); else { n1 = ((mol->cell->flags[0] != 0) * 4 + (mol->cell->flags[1] != 0) * 2 + (mol->cell->flags[2] != 0)); - *actp = MolActionNew(gMolActionSetBox, &(mol->cell->axes[0]), &(mol->cell->axes[1]), &(mol->cell->axes[2]), &(mol->cell->origin), n1); + *actp = MolActionNew(gMolActionSetBox, &(mol->cell->axes[0]), &(mol->cell->axes[1]), &(mol->cell->axes[2]), &(mol->cell->origin), n1, convertCoordinates); } for (n1 = 0; n1 < 4; n1++) v[n1] = *((Vector *)(action->args[n1].u.arval.ptr)); @@ -1374,7 +1391,7 @@ s_MolActionSetBox(Molecule *mol, MolAction *action, MolAction **actp) for (n1 = 0; n1 < 3; n1++) flags[n1] = ((n2 >> (2 - n1)) & 1); } - MoleculeSetPeriodicBox(mol, &v[0], &v[1], &v[2], &v[3], flags); + MoleculeSetPeriodicBox(mol, &v[0], &v[1], &v[2], &v[3], flags, convertCoordinates); } return 0; } @@ -1411,7 +1428,7 @@ s_MolActionSetBoxForFrames(Molecule *mol, MolAction *action, MolAction **actp) /* Set the current cell (no change on the periodic flags) */ vp2 = mol->frame_cells + mol->cframe * 4; - MoleculeSetPeriodicBox(mol, vp2, vp2 + 1, vp2 + 2, vp2 + 3, mol->cell->flags); + MoleculeSetPeriodicBox(mol, vp2, vp2 + 1, vp2 + 2, vp2 + 3, mol->cell->flags, 0); return 0; } diff --git a/MolLib/Molecule.c b/MolLib/Molecule.c index 72aa54c..d66f0dc 100755 --- a/MolLib/Molecule.c +++ b/MolLib/Molecule.c @@ -1163,7 +1163,7 @@ MoleculeLoadMbsfFile(Molecule *mp, const char *fname, char *errbuf, int errbufsi 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]); + MoleculeSetPeriodicBox(mp, vs, vs + 1, vs + 2, vs + 3, cbuf[0], 0); if (has_sigma) { if (ReadLine(buf, sizeof buf, fp, &lineNumber) <= 0) { snprintf(errbuf, errbufsize, "line %d: sigma for cell parameters are missing", lineNumber); @@ -3526,7 +3526,7 @@ MoleculeReadCoordinatesFromDcdFile(Molecule *mp, const char *fname, char *errbuf vpp[3].x = vpp[3].y = vpp[3].z = 0.0; if (mp->cell == NULL) { /* Create periodicity if not present */ - MolActionCreateAndPerform(mp, gMolActionSetBox, &vpp[0], &vpp[1], &vpp[2], &vpp[3], 7); + MolActionCreateAndPerform(mp, gMolActionSetBox, &vpp[0], &vpp[1], &vpp[2], &vpp[3], 7, 0); } } } @@ -3602,7 +3602,7 @@ MoleculeReadExtendedInfo(Molecule *mp, const char *fname, char *errbuf, int errb vv = mp->cell->origin; else vv.x = vv.y = vv.z = 0.0; - MoleculeSetPeriodicBox(mp, &v[0], &v[1], &v[2], &vv, flags); + MoleculeSetPeriodicBox(mp, &v[0], &v[1], &v[2], &vv, flags, 0); } else if (strncmp(buf, "Bounding box origin:", 20) == 0) { if (mp->cell != NULL) { v[0] = mp->cell->axes[0]; @@ -3623,7 +3623,7 @@ MoleculeReadExtendedInfo(Molecule *mp, const char *fname, char *errbuf, int errb vv.x = d[0]; vv.y = d[1]; vv.z = d[2]; - MoleculeSetPeriodicBox(mp, &v[0], &v[1], &v[2], &vv, flags); + MoleculeSetPeriodicBox(mp, &v[0], &v[1], &v[2], &vv, flags, 0); } } fclose(fp); @@ -8939,16 +8939,16 @@ MoleculeSetCell(Molecule *mp, Double a, Double b, Double c, Double alpha, Double return; __MoleculeLock(mp); memset(&cmat, 0, sizeof(Transform)); + if (mp->cell != NULL) + memmove(&cmat, &(mp->cell->rtr), sizeof(Transform)); + else + memmove(&cmat, &gIdentityTransform, sizeof(Transform)); if (a == 0.0) { if (mp->cell != NULL) { - memmove(&cmat, &(mp->cell->tr), sizeof(Transform)); free(mp->cell); mp->needsMDRebuild = 1; - } else { - cmat[0] = cmat[4] = cmat[8] = 1.0; } mp->cell = NULL; - /* mp->is_xtal_coord = 0; */ } else { cp = mp->cell; if (cp == NULL) { @@ -8956,13 +8956,8 @@ MoleculeSetCell(Molecule *mp, Double a, Double b, Double c, Double alpha, Double if (cp == NULL) Panic("Low memory during setting cell parameters"); mp->cell = cp; - cmat[0] = cmat[4] = cmat[8] = 1.0; mp->needsMDRebuild = 1; - } else { - /* if (mp->is_xtal_coord) - memmove(&cmat, &(cp->tr), sizeof(Transform)); */ } - /* mp->is_xtal_coord = 1; */ /* alpha, beta, gamma are in degree */ cp->cell[0] = a; cp->cell[1] = b; @@ -9006,7 +9001,7 @@ MoleculeSetCell(Molecule *mp, Double a, Double b, Double c, Double alpha, Double cp->origin.x = cp->origin.y = cp->origin.z = 0.0; cp->flags[0] = cp->flags[1] = cp->flags[2] = 1; MoleculeCalculateCellFromAxes(cp, 0); - TransformMul(cmat, cp->rtr, cmat); + TransformMul(cmat, cp->tr, cmat); } /* Update the coordinates (if requested) */ @@ -9172,23 +9167,27 @@ MoleculeSetAnisoBySymop(Molecule *mp, int idx) } int -MoleculeSetPeriodicBox(Molecule *mp, const Vector *ax, const Vector *ay, const Vector *az, const Vector *ao, const char *periodic) +MoleculeSetPeriodicBox(Molecule *mp, const Vector *ax, const Vector *ay, const Vector *az, const Vector *ao, const char *periodic, int convertCoordinates) { static Vector zeroVec = {0, 0, 0}; -/* static Transform identityTransform = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}; */ XtalCell b; - int n; + Transform cmat; + int i, n; + Atom *ap; if (mp == NULL) return 0; + if (mp->cell != NULL) + memmove(&cmat, &(mp->cell->rtr), sizeof(Transform)); + else + memmove(&cmat, &gIdentityTransform, sizeof(Transform)); if (ax == NULL) { if (mp->cell != NULL) { free(mp->cell); mp->needsMDRebuild = 1; } mp->cell = NULL; - /* mp->is_xtal_coord = 0; */ return 0; - } + } memset(&b, 0, sizeof(b)); b.axes[0] = (ax != NULL ? *ax : zeroVec); b.axes[1] = (ay != NULL ? *ay : zeroVec); @@ -9214,9 +9213,25 @@ MoleculeSetPeriodicBox(Molecule *mp, const Vector *ax, const Vector *ay, const V mp->cell = (XtalCell *)calloc(sizeof(XtalCell), 1); if (mp->cell != NULL) { memmove(mp->cell, &b, sizeof(XtalCell)); + TransformMul(cmat, b.tr, cmat); + /* Update the coordinates (if requested) */ + if (convertCoordinates) { + for (i = 0, ap = mp->atoms; i < mp->natoms; i++, ap = ATOM_NEXT(ap)) { + TransformVec(&(ap->r), cmat, &(ap->r)); + } + } + + /* Update the anisotropic parameters */ + for (i = 0, ap = mp->atoms; i < mp->natoms; i++, ap = ATOM_NEXT(ap)) { + Aniso *anp = ap->aniso; + if (anp != NULL) { + MoleculeSetAniso(mp, i, 0, anp->bij[0], anp->bij[1], anp->bij[2], anp->bij[3], anp->bij[4], anp->bij[5], anp->bsig); + } + } n = 0; } else n = -2; /* Out of memory */ __MoleculeUnlock(mp); + sMoleculeNotifyChangeAppearance(mp); return n; } @@ -9715,7 +9730,7 @@ MoleculeSelectFrame(Molecule *mp, int frame, int copyback) } /* Set the cell from the frame array */ if (frame != cframe && frame >= 0 && frame < mp->nframe_cells) { - MoleculeSetPeriodicBox(mp, &mp->frame_cells[frame * 4], &mp->frame_cells[frame * 4 + 1], &mp->frame_cells[frame * 4 + 2], &mp->frame_cells[frame * 4 + 3], mp->cell->flags); + MoleculeSetPeriodicBox(mp, &mp->frame_cells[frame * 4], &mp->frame_cells[frame * 4 + 1], &mp->frame_cells[frame * 4 + 2], &mp->frame_cells[frame * 4 + 3], mp->cell->flags, 0); modified = 1; MoleculeAmendBySymmetry(mp, NULL, NULL, NULL); } diff --git a/MolLib/Molecule.h b/MolLib/Molecule.h index 35aa31c..f5faaaf 100755 --- a/MolLib/Molecule.h +++ b/MolLib/Molecule.h @@ -375,7 +375,7 @@ void AtomRefRelease(AtomRef *aref); void MoleculeSetCell(Molecule *mp, Double a, Double b, Double c, Double alpha, Double beta, Double gamma, int convertCoordinates); void MoleculeSetAniso(Molecule *mp, int n1, int type, Double x11, Double x22, Double x33, Double x12, Double x13, Double x23, const Double *sigmap); void MoleculeSetAnisoBySymop(Molecule *mp, int idx); -int MoleculeSetPeriodicBox(Molecule *mp, const Vector *ax, const Vector *ay, const Vector *az, const Vector *ao, const char *periodic); +int MoleculeSetPeriodicBox(Molecule *mp, const Vector *ax, const Vector *ay, const Vector *az, const Vector *ao, const char *periodic, int convertCoordinates); int MoleculeReadCoordinatesFromFile(Molecule *mp, const char *fname, const char *ftype, char *errbuf, int errbufsize); int MoleculeReadCoordinatesFromPdbFile(Molecule *mp, const char *fname, char *errbuf, int errbufsize); diff --git a/MolLib/Ruby_bind/ruby_bind.c b/MolLib/Ruby_bind/ruby_bind.c index 9f83251..c40190b 100644 --- a/MolLib/Ruby_bind/ruby_bind.c +++ b/MolLib/Ruby_bind/ruby_bind.c @@ -5543,7 +5543,7 @@ s_Molecule_Cell(VALUE self) * 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. + the coordinates are transformed so that the fractional coordinates remain the same. */ static VALUE s_Molecule_SetCell(int argc, VALUE *argv, VALUE self) @@ -5617,7 +5617,7 @@ s_Molecule_Box(VALUE self) /* * call-seq: - * set_box(avec, bvec, cvec, origin = [0, 0, 0], flags = [1, 1, 1]) + * set_box(avec, bvec, cvec, origin = [0, 0, 0], flags = [1, 1, 1], convert_coordinates = nil) * set_box(d, origin = [0, 0, 0]) * set_box * @@ -5626,6 +5626,7 @@ s_Molecule_Box(VALUE self) as the box vector. Flags, if present, is a 3-member array of Integers defining whether the system is periodic along the axis. + If convert_coordinates is true, then the coordinates are converted so that the fractional coordinates remain the same. 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. @@ -5634,15 +5635,15 @@ static VALUE s_Molecule_SetBox(VALUE self, VALUE aval) { Molecule *mol; - VALUE v[5]; + VALUE v[6]; static Vector ax[3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; Vector vv[3]; Vector origin = {0, 0, 0}; char flags[3]; Double d; - int i; + int i, convertCoordinates = 0; Data_Get_Struct(self, Molecule, mol); - for (i = 0; i < 5; i++) { + for (i = 0; i < 6; i++) { if (i < RARRAY_LEN(aval)) v[i] = (RARRAY_PTR(aval))[i]; else v[i] = Qnil; @@ -5678,8 +5679,10 @@ s_Molecule_SetBox(VALUE self, VALUE aval) flags[i] = (NUM2INT(rb_Integer(val)) != 0); } } + if (RTEST(v[5])) + convertCoordinates = 1; } - MolActionCreateAndPerform(mol, gMolActionSetBox, &(vv[0]), &(vv[1]), &(vv[2]), &origin, (flags[0] * 4 + flags[1] * 2 + flags[2])); + MolActionCreateAndPerform(mol, gMolActionSetBox, &(vv[0]), &(vv[1]), &(vv[2]), &origin, (flags[0] * 4 + flags[1] * 2 + flags[2]), convertCoordinates); return self; } @@ -7017,7 +7020,7 @@ s_Molecule_GetCoordFromFrame(int argc, VALUE *argv, VALUE self) free(vp); if (RTEST(cval) && mol->cell != NULL && mol->frame_cells != NULL && index < mol->nframe_cells) { vp = mol->frame_cells + index * 4; - MolActionCreateAndPerform(mol, gMolActionSetBox, vp, vp + 1, vp + 2, vp + 3, -1); + MolActionCreateAndPerform(mol, gMolActionSetBox, vp, vp + 1, vp + 2, vp + 3, -1, 0); } IntGroupIteratorRelease(&iter); } diff --git a/MolLib/Ruby_bind/ruby_md.c b/MolLib/Ruby_bind/ruby_md.c index b3c2027..6b1c17b 100644 --- a/MolLib/Ruby_bind/ruby_md.c +++ b/MolLib/Ruby_bind/ruby_md.c @@ -121,7 +121,7 @@ s_MDArena_Run_or_minimize(VALUE self, VALUE arg, int minimize) vp[1] = arena->mol->cell->axes[1]; vp[2] = arena->mol->cell->axes[2]; vp[3] = arena->mol->cell->origin; - MolActionCreateAndPerform(arena->xmol, gMolActionSetBox, vp, vp + 1, vp + 2, vp + 3, -1); + MolActionCreateAndPerform(arena->xmol, gMolActionSetBox, vp, vp + 1, vp + 2, vp + 3, -1, 0); } } /* Copy forces (this is valid even for "zero-step" run) */ diff --git a/wxSources/MoleculeView.cpp b/wxSources/MoleculeView.cpp index 95d363e..37eec3a 100755 --- a/wxSources/MoleculeView.cpp +++ b/wxSources/MoleculeView.cpp @@ -632,7 +632,7 @@ MoleculeView::SelectTable(int idx) MoleculeLock(mview->mol); MainView_refreshTable(mview); MoleculeUnlock(mview->mol); - if (idx == kMainViewParameterTableIndex || idx == kMainViewMOTableIndex) { + if (idx >= kMainViewParameterTableIndex) { MainViewCallback_setTableSelection(mview, NULL); } } -- 2.11.0