• R/O
  • SSH
  • HTTPS

molby: Commit


Commit MetaInfo

Revision56 (tree)
Time2010-05-16 12:09:36
Authortoshinagata1964

Log Message

The native format (mbsf) now preserves the display conditions, such as scale, orientation, and show/hide unit cell, periodic images, etc.

Change Summary

Incremental Difference

--- trunk/Scripts/loadsave.rb (revision 55)
+++ trunk/Scripts/loadsave.rb (revision 56)
@@ -438,6 +438,7 @@
438438 }
439439 fp.print " $END\n"
440440 fp.close
441+ return true
441442 end
442443
443444 def savecom(filename)
@@ -459,6 +460,7 @@
459460 }
460461 fp.print "\n"
461462 fp.close
463+ return true
462464 end
463465
464466 alias :loadgjf :loadcom
--- trunk/wxSources/MyDocument.cpp (revision 55)
+++ trunk/wxSources/MyDocument.cpp (revision 56)
@@ -159,8 +159,8 @@
159159 MoleculeView *view = (MoleculeView *)GetFirstView();
160160 if (view != NULL) {
161161 MainView_setMolecule(view->mview, aMolecule);
162- if (aMolecule->natoms >= 1000)
163- view->mview->lineMode = 1;
162+ /* if (aMolecule->natoms >= 1000)
163+ view->mview->lineMode = 1; */
164164 }
165165 }
166166
@@ -213,9 +213,12 @@
213213 Molecule *newmol;
214214 p = strdup((const char *)file.mb_str(wxConvFile));
215215 newmol = MoleculeNew();
216+ SetMolecule(newmol);
217+ MoleculeRelease(newmol);
216218 SetUndoEnabled(false);
217219 if (MolActionCreateAndPerform(newmol, SCRIPT_ACTION("s"), "molload", p) != 0) {
218220 free(p);
221+ SetMolecule(NULL);
219222 SetUndoEnabled(true);
220223 return false;
221224 }
@@ -232,10 +235,14 @@
232235 MoleculeReadExtendedInfo(newmol, p, buf, sizeof buf);
233236 }
234237 free(p);
235- SetMolecule(newmol);
236238 Modify(false);
237239 GetCommandProcessor()->MarkAsSaved();
238240 hasFile = true;
241+ if (newmol->natoms > 1000)
242+ newmol->mview->lineMode = 1;
243+ if (TrackballGetModifyCount(newmol->mview->track) == 0)
244+ MainView_resizeToFit(newmol->mview);
245+ MoleculeCallback_notifyModification(newmol, 0);
239246 SetUndoEnabled(true);
240247 return true;
241248 }
--- trunk/wxSources/MyDocManager.cpp (revision 55)
+++ trunk/wxSources/MyDocManager.cpp (revision 56)
@@ -23,7 +23,7 @@
2323 END_EVENT_TABLE()
2424
2525 static const char *sReadOnlyTypes[] = {
26- "out", "fchk", "log", NULL
26+ "out", "fchk", "log", "dat", "ins", "res", "xyz", NULL
2727 };
2828
2929 void
--- trunk/Makefile (revision 55)
+++ trunk/Makefile (revision 56)
@@ -21,7 +21,7 @@
2121 endif
2222
2323 WXLIB_LIST = core,base,gl,adv
24-OBJECTS = ConsoleFrame.o GlobalParameterFrame.o GlobalParameterFilesFrame.o MoleculeView.o MyApp.o MyCommand.o MyDocument.o MyGLCanvas.o MySlider.o MyClipboardData.o ProgressFrame.o MyListCtrl.o MyDocManager.o wxKillAddition.o RubyDialogFrame.o MyVersion.o MyThread.o MolLib.a Ruby_bind.a
24+OBJECTS = ConsoleFrame.o GlobalParameterFrame.o GlobalParameterFilesFrame.o MoleculeView.o MyApp.o MyCommand.o MyDocument.o MyGLCanvas.o MySlider.o MyClipboardData.o ProgressFrame.o MyListCtrl.o MyDocManager.o wxKillAddition.o docview.o RubyDialogFrame.o MyVersion.o MyThread.o MolLib.a Ruby_bind.a
2525 RUBY_EXTLIB = scanf.rb
2626
2727 ifeq ($(TARGET_PLATFORM),MAC)
--- trunk/MolLib/Trackball.c (revision 55)
+++ trunk/MolLib/Trackball.c (revision 56)
@@ -117,6 +117,12 @@
117117 }
118118 }
119119
120+float
121+TrackballGetScale(const Trackball *track)
122+{
123+ NULL_CHECK(track, "TrackballGetScale");
124+ return track->tempScale + track->scale;
125+}
120126
121127 /* Get the current rotation (in GL format) */
122128 //- (void)getRotate:(float *)a
@@ -190,6 +196,12 @@
190196 }
191197 }
192198
199+int
200+TrackballGetModifyCount(Trackball *track)
201+{
202+ return (track != NULL ? track->modifyCount : 0);
203+}
204+
193205 void
194206 TrackballReset(Trackball *track)
195207 {
@@ -201,6 +213,7 @@
201213 track->quat[0] = track->tempQuat[0] = 1.0;
202214 track->tempScale = 0;
203215 track->scale = 0;
216+ track->modifyCount++;
204217 }
205218
206219 void
@@ -209,9 +222,25 @@
209222 NULL_CHECK(track, "TrackballSetScale");
210223 track->tempScale = 0;
211224 track->scale = scale;
225+ track->modifyCount++;
212226 }
213227
214228 void
229+TrackballSetRotate(Trackball *track, const float *a)
230+{
231+ float k;
232+ NULL_CHECK(track, "TrackballSetRotate");
233+ track->tempQuat[0] = 1.0;
234+ track->tempQuat[1] = track->tempQuat[2] = track->tempQuat[3] = 0.0;
235+ track->quat[0] = cos(a[0] * 0.5 * kDeg2Rad);
236+ k = sin(a[0] * 0.5 * kDeg2Rad);
237+ track->quat[1] = k * a[1];
238+ track->quat[2] = k * a[2];
239+ track->quat[3] = k * a[3];
240+ track->modifyCount++;
241+}
242+
243+void
215244 TrackballSetTranslate(Trackball *track, const float *a)
216245 {
217246 NULL_CHECK(track, "TrackballSetTranslate");
@@ -219,6 +248,7 @@
219248 track->trans[0] = a[0];
220249 track->trans[1] = a[1];
221250 track->trans[2] = a[2];
251+ track->modifyCount++;
222252 }
223253
224254 #pragma mark ====== Mouse operations ======
--- trunk/MolLib/Trackball.h (revision 55)
+++ trunk/MolLib/Trackball.h (revision 56)
@@ -62,6 +62,8 @@
6262 float tempTrans[3]; /* Temporary translation */
6363 float scale; /* Scale */
6464 float tempScale; /* Temporary scale */
65+
66+ int modifyCount;
6567 } Trackball;
6668
6769 Trackball *TrackballNew(void);
@@ -68,6 +70,7 @@
6870 void TrackballRetain(Trackball *track);
6971 void TrackballRelease(Trackball *track);
7072
73+float TrackballGetScale(const Trackball *track);
7174 void TrackballGetRotate(const Trackball *track, float *a);
7275 void TrackballGetTranslate(const Trackball *track, float *a);
7376 void TrackballGetPerspective(const Trackball *track, float *a);
@@ -74,8 +77,11 @@
7477
7578 void TrackballReset(Trackball *track);
7679 void TrackballSetScale(Trackball *track, float scale);
80+void TrackballSetRotate(Trackball *track, const float *a);
7781 void TrackballSetTranslate(Trackball *track, const float *a);
7882
83+int TrackballGetModifyCount(Trackball *track);
84+
7985 void TrackballStartDragging(Trackball *track, const float *mousePos, TrackballMode mode);
8086 void TrackballSetTemporaryRotation(Trackball *track, const float *q);
8187 void TrackballDrag(Trackball *track, const float *mousePos);
--- trunk/MolLib/Molecule.c (revision 55)
+++ trunk/MolLib/Molecule.c (revision 56)
@@ -329,12 +329,23 @@
329329 MoleculeExchange(Molecule *mp1, Molecule *mp2)
330330 {
331331 Molecule mp_temp;
332+ struct MainView *mview1, *mview2;
333+ struct MDArena *arena1, *arena2;
334+ /* mview and arena must be kept as they are */
335+ mview1 = mp1->mview;
336+ mview2 = mp2->mview;
337+ arena1 = mp1->arena;
338+ arena2 = mp2->arena;
332339 /* 'natoms' is the first member to be copied */
333340 int ofs = offsetof(Molecule, natoms);
334341 memmove((char *)(&mp_temp) + ofs, (char *)mp1 + ofs, sizeof(Molecule) - ofs);
335342 memmove((char *)mp1 + ofs, (char *)mp2 + ofs, sizeof(Molecule) - ofs);
336343 memmove((char *)mp2 + ofs, (char *)(&mp_temp) + ofs, sizeof(Molecule) - ofs);
337- if (mp1->arena != NULL && mp1->arena->mol == mp2)
344+ mp1->arena = arena1;
345+ mp2->arena = arena2;
346+ mp1->mview = mview1;
347+ mp2->mview = mview2;
348+/* if (mp1->arena != NULL && mp1->arena->mol == mp2)
338349 mp1->arena->mol = mp1;
339350 if (mp1->arena != NULL && mp1->arena->xmol == mp2)
340351 mp1->arena->xmol = mp1;
@@ -341,7 +352,7 @@
341352 if (mp2->arena != NULL && mp2->arena->mol == mp1)
342353 mp2->arena->mol = mp2;
343354 if (mp2->arena != NULL && mp2->arena->xmol == mp1)
344- mp2->arena->xmol = mp2;
355+ mp2->arena->xmol = mp2; */
345356 }
346357
347358 #pragma mark ====== Mutex ======
@@ -470,13 +481,15 @@
470481 MoleculeLoadMbsfFile(Molecule *mol, const char *fname, char *errbuf, int errbufsize)
471482 {
472483 FILE *fp;
473- Molecule *mp;
474484 char buf[1024];
475485 int i, j, k, n, err, fn, nframes;
476486 int lineNumber;
487+ Molecule *mp;
477488 int ibuf[12];
478489 Int iibuf[4];
479490 double dbuf[12];
491+ int mview_ibuf[16];
492+ float mview_fbuf[8];
480493 char cbuf[12][6];
481494 const char **pp;
482495 char *bufp, *valp, *comp;
@@ -484,6 +497,7 @@
484497 Double *dp;
485498 Vector v;
486499 Atom *ap;
500+ const int kUndefined = -10000000;
487501 err = 0;
488502 if (errbuf == NULL) {
489503 errbuf = buf;
@@ -490,12 +504,20 @@
490504 errbufsize = 1024;
491505 }
492506 errbuf[0] = 0;
493- mp = MoleculeNew();
507+ if (mol->natoms != 0) {
508+ snprintf(errbuf, errbufsize, "The molecule must be empty");
509+ return 1;
510+ }
494511 fp = fopen(fname, "rb");
495512 if (fp == NULL) {
496513 snprintf(errbuf, errbufsize, "Cannot open file");
497514 return 1;
498515 }
516+ mp = MoleculeNew(); /* Temporary molecule */
517+ for (i = 0; i < 8; i++)
518+ mview_fbuf[i] = kUndefined;
519+ for (i = 0; i < 16; i++)
520+ mview_ibuf[i] = kUndefined;
499521 /* flockfile(fp); */
500522 lineNumber = 0;
501523 fn = 0;
@@ -965,6 +987,57 @@
965987 free(bufp);
966988 }
967989 continue;
990+ } else if (strstr(buf, "!:trackball") == buf) {
991+ i = 0;
992+ while (ReadLine(buf, sizeof buf, fp, &lineNumber) > 0) {
993+ if (buf[0] == '!')
994+ continue;
995+ if (buf[0] == '\n')
996+ break;
997+ /* scale; trx try trz; theta_deg x y z */
998+ if ((i == 0 && sscanf(buf, "%f", &mview_fbuf[0]) < 1)
999+ || (i == 1 && sscanf(buf, "%f %f %f",
1000+ &mview_fbuf[1], &mview_fbuf[2], &mview_fbuf[3]) < 3)
1001+ || (i == 2 && sscanf(buf, "%f %f %f %f",
1002+ &mview_fbuf[4], &mview_fbuf[5], &mview_fbuf[6], &mview_fbuf[7]) < 4)) {
1003+ snprintf(errbuf, errbufsize, "line %d: bad trackball format", lineNumber);
1004+ goto exit;
1005+ }
1006+ i++;
1007+ }
1008+ continue;
1009+ } else if (strstr(buf, "!:view") == buf) {
1010+ while (ReadLine(buf, sizeof buf, fp, &lineNumber) > 0) {
1011+ if (buf[0] == '!')
1012+ continue;
1013+ if (buf[0] == '\n')
1014+ break;
1015+ bufp = buf;
1016+ comp = strsep(&bufp, " \t");
1017+ if (bufp != NULL) {
1018+ while (*bufp == ' ' || *bufp == '\t')
1019+ bufp++;
1020+ valp = strsep(&bufp, "\n");
1021+ } else valp = NULL;
1022+ /* In the following, the redundant "!= NULL" is to suppress suprious warning */
1023+ if ((strcmp(comp, "show_unit_cell") == 0 && (i = 1))
1024+ || (strcmp(comp, "show_periodic_box") == 0 && (i = 2))
1025+ || (strcmp(comp, "show_expanded_atoms") == 0 && (i = 3))
1026+ || (strcmp(comp, "show_ellipsoids") == 0 && (i = 4))
1027+ || (strcmp(comp, "show_hydrogens") == 0 && (i = 5))
1028+ || (strcmp(comp, "show_dummy_atoms") == 0 && (i = 6))
1029+ || (strcmp(comp, "show_rotation_center") == 0 && (i = 7))
1030+ || (strcmp(comp, "show_graphite_flag") == 0 && (i = 8))
1031+ || (strcmp(comp, "show_periodic_image_flag") == 0 && (i = 9))
1032+ || (strcmp(comp, "show_graphite") == 0 && (i = 10))) {
1033+ mview_ibuf[i - 1] = atoi(valp);
1034+ } else if (strcmp(comp, "show_periodic_image") == 0) {
1035+ sscanf(valp, "%d %d %d %d %d %d",
1036+ &mview_ibuf[10], &mview_ibuf[11], &mview_ibuf[12],
1037+ &mview_ibuf[13], &mview_ibuf[14], &mview_ibuf[15]);
1038+ }
1039+ }
1040+ continue;
9681041 }
9691042 /* Unknown sections are silently ignored */
9701043 }
@@ -976,14 +1049,47 @@
9761049 exit:
9771050 fclose(fp);
9781051 if (errbuf[0] != 0) {
979- free(mp);
1052+ MoleculeRelease(mp);
9801053 return -1;
9811054 } else {
9821055 MoleculeExchange(mp, mol);
9831056 MoleculeRelease(mp);
1057+ if (mol->mview != NULL) {
1058+ if (mview_ibuf[0] != kUndefined)
1059+ mol->mview->showUnitCell = mview_ibuf[0];
1060+ if (mview_ibuf[1] != kUndefined)
1061+ mol->mview->showPeriodicBox = mview_ibuf[1];
1062+ if (mview_ibuf[2] != kUndefined)
1063+ mol->mview->showExpandedAtoms = mview_ibuf[2];
1064+ if (mview_ibuf[3] != kUndefined)
1065+ mol->mview->showEllipsoids = mview_ibuf[3];
1066+ if (mview_ibuf[4] != kUndefined)
1067+ mol->mview->showHydrogens = mview_ibuf[4];
1068+ if (mview_ibuf[5] != kUndefined)
1069+ mol->mview->showDummyAtoms = mview_ibuf[5];
1070+ if (mview_ibuf[6] != kUndefined)
1071+ mol->mview->showRotationCenter = mview_ibuf[6];
1072+ if (mview_ibuf[7] != kUndefined)
1073+ mol->mview->showGraphiteFlag = mview_ibuf[7];
1074+ if (mview_ibuf[8] != kUndefined)
1075+ mol->mview->showPeriodicImageFlag = mview_ibuf[8];
1076+ if (mview_ibuf[9] != kUndefined)
1077+ mol->mview->showGraphite = mview_ibuf[9];
1078+ for (i = 0; i < 6; i++) {
1079+ if (mview_ibuf[10 + i] != kUndefined)
1080+ mol->mview->showPeriodicImage[i] = mview_ibuf[10 + i];
1081+ }
1082+ if (mol->mview->track != NULL) {
1083+ if (mview_fbuf[0] != kUndefined)
1084+ TrackballSetScale(mol->mview->track, mview_fbuf[0]);
1085+ if (mview_fbuf[1] != kUndefined)
1086+ TrackballSetTranslate(mol->mview->track, mview_fbuf + 1);
1087+ if (mview_fbuf[4] != kUndefined)
1088+ TrackballSetRotate(mol->mview->track, mview_fbuf + 4);
1089+ }
1090+ }
9841091 }
9851092 return 0;
986-
9871093 }
9881094
9891095 int
@@ -2981,8 +3087,38 @@
29813087 fprintf(fp, "%d %.8f %.8f %.8f\n", i, ap->f.x, ap->f.y, ap->f.z);
29823088 }
29833089 fprintf(fp, "\n");
2984-
29853090 }
3091+
3092+ if (mp->mview != NULL) {
3093+ float f[4];
3094+ if (mp->mview->track != NULL) {
3095+ fprintf(fp, "!:trackball\n");
3096+ fprintf(fp, "! scale; trx try trz; theta_deg x y z\n");
3097+ f[0] = TrackballGetScale(mp->mview->track);
3098+ fprintf(fp, "%f\n", f[0]);
3099+ TrackballGetTranslate(mp->mview->track, f);
3100+ fprintf(fp, "%f %f %f\n", f[0], f[1], f[2]);
3101+ TrackballGetRotate(mp->mview->track, f);
3102+ fprintf(fp, "%f %f %f %f\n", f[0], f[1], f[2], f[3]);
3103+ fprintf(fp, "\n");
3104+ }
3105+ fprintf(fp, "!:view\n");
3106+ fprintf(fp, "show_unit_cell %d\n", mp->mview->showUnitCell);
3107+ fprintf(fp, "show_periodic_box %d\n", mp->mview->showPeriodicBox);
3108+ fprintf(fp, "show_expanded_atoms %d\n", mp->mview->showExpandedAtoms);
3109+ fprintf(fp, "show_ellipsoids %d\n", mp->mview->showEllipsoids);
3110+ fprintf(fp, "show_hydrogens %d\n", mp->mview->showHydrogens);
3111+ fprintf(fp, "show_dummy_atoms %d\n", mp->mview->showDummyAtoms);
3112+ fprintf(fp, "show_rotation_center %d\n", mp->mview->showRotationCenter);
3113+ fprintf(fp, "show_graphite_flag %d\n", mp->mview->showGraphiteFlag);
3114+ fprintf(fp, "show_graphite %d\n", mp->mview->showGraphite);
3115+ fprintf(fp, "show_periodic_image_flag %d\n", mp->mview->showPeriodicImageFlag);
3116+ fprintf(fp, "show_periodic_image %d %d %d %d %d %d\n",
3117+ mp->mview->showPeriodicImage[0], mp->mview->showPeriodicImage[1],
3118+ mp->mview->showPeriodicImage[2], mp->mview->showPeriodicImage[3],
3119+ mp->mview->showPeriodicImage[4], mp->mview->showPeriodicImage[5]);
3120+ fprintf(fp, "\n");
3121+ }
29863122
29873123 fclose(fp);
29883124 return 0;
--- trunk/MolLib/MainView.c (revision 55)
+++ trunk/MolLib/MainView.c (revision 56)
@@ -99,7 +99,7 @@
9999 MoleculeRetain(mol);
100100 mol->mview = mview; /* No retain */
101101 MainViewCallback_moleculeReplaced(mview, mol);
102- MainView_resizeToFit(mview);
102+ /* MainView_resizeToFit(mview); */
103103 MoleculeCallback_notifyModification(mol, 0);
104104 /* MainViewCallback_setNeedsDisplay(mview, 1); */
105105 }
--- trunk/MolLib/MainView.h (revision 55)
+++ trunk/MolLib/MainView.h (revision 56)
@@ -99,6 +99,7 @@
9999 float bondRadius; /* in angstrom */
100100 float probabilityScale;
101101 float dimension;
102+
102103 Byte showUnitCell;
103104 Byte showPeriodicBox;
104105 Byte showExpandedAtoms;
--- trunk/MolLib/Ruby_bind/ruby_bind.c (revision 55)
+++ trunk/MolLib/Ruby_bind/ruby_bind.c (revision 56)
@@ -5268,10 +5268,7 @@
52685268 if (MoleculeExtract(mol1, &mol2, ig, (dummy_flag != Qnil && dummy_flag != Qfalse)) != 0) {
52695269 retval = Qnil;
52705270 } else {
5271- retval = s_Molecule_Alloc(rb_cMolecule);
5272- Data_Get_Struct(retval, Molecule, mol1);
5273- MoleculeExchange(mol1, mol2);
5274- MoleculeRelease(mol2);
5271+ retval = ValueFromMolecule(mol2);
52755272 }
52765273 IntGroupRelease(ig);
52775274 return retval;
Show on old repository browser