Skip to content

Commit b157a2c

Browse files
authored
Merge pull request #42 from briling/refactoring-and-fixes
- Update readme and man - Move molecule into pbc upon reading - Fix negative argument for `frame:` - Add warnings
2 parents 52e351d + 35d05d9 commit b157a2c

File tree

13 files changed

+135
-90
lines changed

13 files changed

+135
-90
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ Show the reference:
7474
| `cell:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf` | cell parameters in Å |
7575
| `shell:b%lf,%lf` | spheres radii in a.u. |
7676
| `shell:%lf,%lf` | spheres radii in Å |
77+
| `cell:0` | disable PBC from the extended xyz file header |
78+
| `cell:b%%lf[,%%lf,%%lf[,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf]]` | cubic / orthogonal / non-orhogonal cell parameters in a.u. |
79+
| `cell:%%lf[,%%lf,%%lf[,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf]]` | cubic / orthogonal / non-orhogonal cell parameters in Å |
80+
| `shell:b%%lf[,%%lf] | sphere(s) radii in a.u. |
81+
| `shell:%%lf[,%%lf] | sphere(s) radii in Å |
7782
| `center:%d` | origin is geometric center (`1`, default) / center of mass (`2`) / as is (`0`) |
7883
| `inertia:%d` | if rotate molecules wrt axis of inertia (`1`) or not (`0`, default) |
7984
| `gui:%d` | normal (default `1`) / headless (`0`) mode |
@@ -112,9 +117,9 @@ Show the reference:
112117
| `x` | print molecule (Priroda input + bonds)
113118
| `z` | print molecule (`.xyz`)
114119
| `p` | print molecule (input for an `.svg` generator)
115-
| `u` | print current rotation matrix
120+
| `u` | print the current rotation matrix
116121
| `m` | save the current frame ([`.xpm`](https://en.wikipedia.org/wiki/X_PixMap) format)
117-
| `f` | save all frames (vibration mode: save all frames to animate the selected normal mode)
122+
| `f` | save all frames starting from the current one (vibration mode: save all frames to animate the selected normal mode)
118123
| |
119124
| `j` | jump to a frame (will be prompted): `enter` to confirm, `esc` to cancel
120125
| |

src/mol/intcoord.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ double intcoord_calc(int r_units_a, int check_n, int z[5], double * r){
4141
}
4242

4343
int intcoord_check(int n, int z[5]){
44+
if(!(z[0]||z[1]||z[2]||z[3]||z[4])){
45+
return 0;
46+
}
4447
switch(z[0]){
4548
case 3 :
4649
if (z[4] < 1 || z[4] > n) z[0] = 0;
@@ -60,9 +63,11 @@ int intcoord_check(int n, int z[5]){
6063
case 5: // TODO
6164
default:
6265
z[0] = 0;
63-
return -1;
6466
}
6567
switch(z[0]){
68+
case 0 :
69+
PRINT_WARN("check the internal coordintate option ('z:')\n");
70+
return -1;
6671
case 1 :
6772
z[3] = 0;
6873
case 2 :

src/v.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main (int argc, char * argv[]) {
8585
dp->n = dp->n%dp->N;
8686
}
8787
else if(dp->n<0){
88-
dp->n = dp->N-(-dp->n)%dp->N;
88+
dp->n = dp->N-((-dp->n+1)%dp->N)-1;
8989
}
9090

9191
if(!ap.ip.gui){

src/v/ac3_draw.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ void ac3_draw(atcoord * ac, rendpars * rend){
6161
XDrawArc(world.dis, world.canv, q>0?world.gc_black:world.gc_dot[1], x-r, y-r, 2*r, 2*r, 0, 360*64);
6262
}
6363

64-
if(rend->num == 1){
64+
if(rend->num == SHOW_NUMBERS){
6565
char text[16];
6666
snprintf(text, sizeof(text), "%d", k+1);
6767
XDRAWSTRING(world.dis, world.canv, world.gc_black, x, y, text, strlen(text));
6868
}
69-
else if(rend->num == -1){
69+
else if(rend->num == SHOW_TYPES){
7070
char text[16];
7171
const char * s = getname(q);
7272
s ? snprintf(text, sizeof(text), "%s", s) : snprintf(text, sizeof(text), "%d", q );
@@ -92,7 +92,7 @@ void ac3_draw(atcoord * ac, rendpars * rend){
9292
}
9393
double dd = BOND_OFFSET * r / sqrt(r2d);
9494
XDrawLine(world.dis, world.canv, world.gc_black, x+dd*dx, y+dd*dy, x1, y1);
95-
if(rend->bonds==2){
95+
if(rend->bonds==SHOW_LENGTHS){
9696
char text[16];
9797
snprintf(text, sizeof(text), "%.3lf", ac->bonds.r[j]);
9898
XDRAWSTRING(world.dis, world.canv, world.gc_black, x+dx/2, y+dy/2, text, strlen(text));

src/v/ac3_read.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55

66
#define EPS_INV 1e-15
77

8+
void mol2cell(atcoord * m){
9+
double rcell[3];
10+
for(int j=0; j<m->n; j++){
11+
double * r = m->r0+j*3;
12+
r3mx(rcell, r, m->cell.rot_to_cell_basis);
13+
for(int i=0; i<3; i++){
14+
if(rcell[i]<-0.5){
15+
rcell[i] += 1.0;
16+
}
17+
else if(rcell[i]>0.5){
18+
rcell[i] -= 1.0;
19+
}
20+
}
21+
r3mx(r, rcell, m->cell.rot_to_lab_basis);
22+
r3cp(m->r+j*3, r);
23+
}
24+
return;
25+
}
26+
827
static void cell_fill(cellpars * cell, const double abc[9]){
928
const double * a = abc+0;
1029
const double * b = abc+3;
@@ -26,21 +45,21 @@ static void cell_fill(cellpars * cell, const double abc[9]){
2645
return;
2746
}
2847

29-
atcoord * atcoord_fill(mol * m0, const int b, const geompars geom, const double cell[9]){
48+
atcoord * atcoord_fill(mol * m0, const render_bonds_t b, const geompars geom, const double cell[9]){
3049
int n = m0->n;
3150

3251
size_t q_size = sizeof(int ) * n;
3352
size_t r_size = sizeof(double) * n*3;
3453
size_t r0_size = sizeof(double) * n*3;
3554
struct {size_t r_size; size_t a_size;} bonds = {0, 0};
36-
if(b!=-1){
55+
if(b!=DISABLE_BONDS){
3756
bonds.a_size = sizeof(int ) * n*BONDS_MAX;
3857
bonds.r_size = sizeof(double) * n*BONDS_MAX;
3958
}
4059
size_t size = sizeof(atcoord) + q_size + r_size + r0_size + bonds.a_size + bonds.r_size;
4160
atcoord * m = calloc(size, 1);
4261

43-
if(b==-1){
62+
if(b==DISABLE_BONDS){
4463
m->r = (double *) (m + 1);
4564
m->r0 = (double *) MEM_END(m,r);
4665
m->q = (int *) MEM_END(m,r0);
@@ -67,8 +86,8 @@ atcoord * atcoord_fill(mol * m0, const int b, const geompars geom, const double
6786
// we should not change m0
6887
position(&((mol){.n=n, .q=m->q, .r=m->r}), NULL, 1);
6988
}
70-
if(geom.center){
71-
center_mol(n, m->r, geom.center==2 ? m->q : NULL);
89+
if(geom.center!=NO_CENTER){
90+
center_mol(n, m->r, geom.center==CENTER_MASS ? m->q : NULL);
7291
}
7392
veccp(n*3, m->r0, m->r);
7493

@@ -84,10 +103,14 @@ atcoord * atcoord_fill(mol * m0, const int b, const geompars geom, const double
84103
cell_fill(&m->cell, cell);
85104
}
86105

106+
if(m->cell.boundary==CELL){
107+
mol2cell(m);
108+
}
109+
87110
return m;
88111
}
89112

90-
atcoord * ac3_read(readpars read, int b, const geompars geom, format_t * format){
113+
atcoord * ac3_read(readpars read, const render_bonds_t b, const geompars geom, format_t * format){
91114

92115
mol * m = NULL;
93116
FILE * f = read.f;

src/v/cli.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static int cli_parse_arg(char * arg, allpars * ap){
141141
}
142142

143143
if(bonds==0){
144-
dp->rend.bonds = -1;
144+
dp->rend.bonds = DISABLE_BONDS;
145145
}
146146

147147
if(tf>0.0){
@@ -188,11 +188,11 @@ static allpars allpars_init(void){
188188
ap.dp.anim.dt = DEFAULT_TIMEOUT;
189189
ap.dp.anal.symtol = DEFAULT_SYMTOL;
190190
ap.dp.bond.rl = 1.0;
191-
ap.dp.geom.center = 1;
191+
ap.dp.geom.center = CENTER_GEOM;
192192

193193
ap.dp.rend.r = 1.0;
194194
ap.dp.rend.scale = 1.0;
195-
ap.dp.rend.bonds = 1;
195+
ap.dp.rend.bonds = SHOW_BONDS;
196196
mx_id(3, ap.dp.rend.ac3rmx);
197197

198198
return ap;

src/v/evr.c

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -194,29 +194,12 @@ void kp_rotz_r(object * ent, drawpars * dp){
194194
return;
195195
}
196196

197-
static void mol2cell(double r[3], cellpars * cell){
198-
double rcell[3];
199-
r3mx(rcell, r, cell->rot_to_cell_basis);
200-
for(int i=0; i<3; i++){
201-
if(rcell[i]<-0.5){
202-
rcell[i] += 1.0;
203-
}
204-
else if(rcell[i]>0.5){
205-
rcell[i] -= 1.0;
206-
}
207-
}
208-
r3mx(r, rcell, cell->rot_to_lab_basis);
209-
return;
210-
}
211-
212197
static void move_pbc(atcoord * m, drawpars * dp, double dr[3]){
213198
for(int j=0; j<m->n; j++){
214-
double * r = m->r0+j*3;
215-
r3add(r, dr);
216-
mol2cell(r, &m->cell);///TODO
217-
r3cp(m->r+j*3, r);
218-
m->rotated = 0;
199+
r3add(m->r0+j*3, dr);
219200
}
201+
mol2cell(m);
202+
m->rotated = 0;
220203
if(dp->rend.bonds>0){
221204
m->bonds.flag = 0;
222205
m->bonds.rl *= RL_MOVE_PBC_SCALE;
@@ -299,28 +282,28 @@ void kp_bw_toggle(object * ent __attribute__ ((unused)), drawpars * dp){
299282

300283
void kp_l_toggle(object * ent, drawpars * dp){
301284
if(dp->rend.bonds>0){
302-
dp->rend.bonds = 1+!(dp->rend.bonds-1);
285+
dp->rend.bonds = dp->rend.bonds==SHOW_BONDS ? SHOW_LENGTHS : SHOW_BONDS;
303286
exp_redraw(ent, dp);
304287
}
305288
return;
306289
}
307290

308291
void kp_b_toggle(object * ent, drawpars * dp){
309-
if(dp->rend.bonds>-1){
310-
dp->rend.bonds = !dp->rend.bonds;
292+
if(dp->rend.bonds!=DISABLE_BONDS){
293+
dp->rend.bonds = dp->rend.bonds==NO_BONDS ? SHOW_BONDS : NO_BONDS;
294+
exp_redraw(ent, dp);
311295
}
312-
exp_redraw(ent, dp);
313296
return;
314297
}
315298

316299
void kp_n_toggle(object * ent, drawpars * dp){
317-
dp->rend.num = (dp->rend.num == 1) ? 0 : 1;
300+
dp->rend.num = (dp->rend.num == SHOW_NUMBERS) ? NO_ATOM_NUMBERS : SHOW_NUMBERS;
318301
exp_redraw(ent, dp);
319302
return;
320303
}
321304

322305
void kp_t_toggle(object * ent, drawpars * dp){
323-
dp->rend.num = (dp->rend.num == -1) ? 0 : -1;
306+
dp->rend.num = (dp->rend.num == SHOW_TYPES) ? NO_ATOM_NUMBERS : SHOW_TYPES;
324307
exp_redraw(ent, dp);
325308
return;
326309
}
@@ -424,8 +407,8 @@ void kp_pg(object * ent, drawpars * dp){
424407
}
425408

426409
void kp_jump(object * ent, drawpars * dp){
427-
if(!dp->ui.input){
428-
dp->ui.input = 1;
410+
if(dp->ui.input==NO_INPUT){
411+
dp->ui.input = INPUT_JUMP;
429412
exp_redraw(ent, dp);
430413
}
431414
return;

src/v/load.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ object * read_files(allpars * ap){
163163
}
164164
else{
165165
dp->anal.intcoord[0] = 0;
166+
for(i++; i<fn; i++){
167+
PRINT_WARN("ignoring file '%s'\n", flist[i]);
168+
}
166169
}
167170

168171
return ent;

src/v/loop.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void process_input(XKeyEvent * event, drawpars * dp){
2929
if(stop_input){
3030
if(stop_input==1){
3131
switch(dp->ui.input){
32-
case(1):
32+
case(INPUT_JUMP):
3333
{
3434
int frame = atoi(dp->ui.input_text);
3535
frame = MAX(1, MIN(frame, dp->N));
@@ -38,7 +38,7 @@ static void process_input(XKeyEvent * event, drawpars * dp){
3838
}
3939
}
4040
memset(dp->ui.input_text, 0, STRLEN);
41-
dp->ui.input=0;
41+
dp->ui.input = NO_INPUT;
4242
}
4343
return;
4444
}
@@ -109,7 +109,7 @@ void main_loop(object * ent, drawpars * dp, ptf kp[NKP]){
109109
}
110110

111111
else if(event->type == KeyPress) {
112-
if(dp->ui.input){
112+
if(dp->ui.input!=NO_INPUT){
113113
process_input(&(event->xkey), dp);
114114
exp_redraw(ent, dp);
115115
}

src/v/man.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,30 @@ void printman(FILE * f, char * exename){
99
\n\
1010
OPTIONS:\n\
1111
\n\
12-
vib:%%d force to show geometries (0) / vibrations (1) \n\
13-
bonds:0 disable bonds\n\
14-
bmax:%%lf max. length of a bond to display\n\
15-
bohr:1 assume input files are in Bohr (default is Å)\n\
16-
dt:%%lf delay between frames in seconds (default %g)\n\
17-
symtol:%%lf tolerance for symmetry determination in Å (default %g) \n\
18-
z:%%d,%%d,%%d,%%d,%%d show an internal coordinate: \n\
19-
1,i,j,0,0 - distance i-j\n\
20-
2,i,j,k,0 - angle i-j-k\n\
21-
3,i,j,k,l - torsion i-j-k-l\n\
22-
rot:%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf rotation matrix to start with (default identity matrix)\n\
23-
frame:%%d frame to start with (default 1)\n\
24-
font:%%s font (xlfd) \n\
25-
colors:%%s colorscheme (\"v\" (default) or \"cpk\") \n\n\
26-
cell:b%%lf,%%lf,%%lf cuboid size in a.u. \n\
27-
cell:%%lf,%%lf,%%lf cuboid size in Å \n\
28-
cell:b%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf cell parameters in a.u. \n\
29-
cell:%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf cell parameters in Å \n\
30-
shell:b%%lf,%%lf spheres radii in a.u. \n\
31-
shell:%%lf,%%lf spheres radii in Å \n\
32-
center:%%d origin is geometric center (1, default) / center of mass (2) / as is (0) \n\
33-
inertia:%%d if rotate molecules wrt axis of inertia (1) or not (0, default) \n\n\
34-
gui:%%d normal (1) / headless (0) mode \n\
35-
com:%%s command sequence for gui:0 \n\
36-
exitcom:%%s command sequence to run on exit (same as for gui:0) \n\
12+
vib:%%d force to show geometries (0) / vibrations (1) \n\
13+
bonds:0 disable bonds\n\
14+
bmax:%%lf max. length of a bond to display\n\
15+
bohr:1 assume input files are in Bohr (default is Å)\n\
16+
dt:%%lf delay between frames in seconds (default %g)\n\
17+
symtol:%%lf tolerance for symmetry determination in Å (default %g) \n\
18+
z:%%d,%%d,%%d,%%d,%%d show an internal coordinate: \n\
19+
1,i,j,0,0 - distance i-j\n\
20+
2,i,j,k,0 - angle i-j-k\n\
21+
3,i,j,k,l - torsion i-j-k-l\n\
22+
rot:%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf rotation matrix to start with (default identity matrix)\n\
23+
frame:%%d frame to start with (default 1)\n\
24+
font:%%s font (xlfd) \n\
25+
colors:%%s colorscheme (\"v\" (default) or \"cpk\") \n\n\
26+
cell:0 disable PBC from the extended xyz file header \n\
27+
cell:b%%lf[,%%lf,%%lf[,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf]] cubic / orthogonal / non-orhogonal cell parameters in a.u. \n\
28+
cell:%%lf[,%%lf,%%lf[,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf]] cubic / orthogonal / non-orhogonal cell parameters in Å \n\
29+
shell:b%%lf[,%%lf] sphere(s) radii in a.u. \n\
30+
shell:%%lf[,%%lf] sphere(s) radii in Å \n\
31+
center:%%d origin is geometric center (1, default) / center of mass (2) / as is (0) \n\
32+
inertia:%%d if rotate molecules wrt axis of inertia (1) or not (0, default) \n\n\
33+
gui:%%d normal (1, default) / headless (0) mode \n\
34+
com:%%s command sequence for gui:0 \n\
35+
exitcom:%%s command sequence to run on exit (same as for gui:0) \n\
3736
\n\
3837
KEYBOARD REFERENCE:\n\
3938
\n\
@@ -44,7 +43,8 @@ void printman(FILE * f, char * exename){
4443
0 go to the first point \n\
4544
= go to the last point \n\
4645
enter/backspace next/previous point \n\
47-
ins play forwards / stop (vibration mode: animate selected normal mode / stop)\n\
46+
ins play forwards / stop \n\
47+
vibration mode: animate selected normal mode / stop\n\
4848
del play backwards / stop \n\
4949
\n\
5050
home/end zoom in/out \n\
@@ -63,9 +63,10 @@ void printman(FILE * f, char * exename){
6363
x print molecule (Priroda input + bonds) \n\
6464
z print molecule (.xyz) \n\
6565
p print molecule (input for an .svg generator) \n\
66-
u print current rotation matrix \n\
66+
u print the current rotation matrix \n\
6767
m save the current frame (.xpm format)\n\
68-
f save all frames (vibration mode: save all frames to animate the selected normal mode)\n\
68+
f save all frames starting from the current one \n\
69+
vibration mode: save all frames to animate the selected normal mode) \n\
6970
\n\
7071
j jump to a frame (will be prompted)\n\
7172
\n\

0 commit comments

Comments
 (0)