Skip to content

Commit

Permalink
Merge branch 'headless'
Browse files Browse the repository at this point in the history
  • Loading branch information
briling committed Aug 9, 2023
2 parents 0bcd105 + 55ba42f commit f7fee1c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 14 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Show the reference:
| `cell:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf` | cell parameters in Å |
| `shell:b%lf,%lf` | spheres radii in a.u. |
| `shell:%lf,%lf` | spheres radii in Å |
| `gui:%d` | normal (default `1`) / headless (`0`) mode |

</details>

Expand Down Expand Up @@ -100,8 +101,20 @@ Show the reference:

</details>

<details open><summary><strong>Mouse</strong></summary>
One can also use the mouse to rotate the molecule and zoom in/out (in development).
<details open><summary><strong>Mouse (in development)</strong></summary>
One can also use the mouse to rotate the molecule and zoom in/out.
</details>

<details open><summary><strong>Headless mode (in development)</strong></summary>

If run in the headless mode with `gui:0`, the symbols from stdio are processed
as if the corresponding keys were pressed in the normal mode.
Right now, only `p`, `x`, `z`, and `.` are available. For example,
```
> echo . | ./v mol/mol0001.xyz gui:0
D*h
```

</details>

## Examples [](#contents)
Expand Down
29 changes: 29 additions & 0 deletions src/v.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static void version(FILE * f){
static drawpars dp_init(void){
drawpars dp;
dp.task = UNKNOWN;
dp.gui = 1;
dp.dt = DEFAULT_TIMEOUT;
memset(dp.fontname, 0, STRLEN);
dp.n = 0;
Expand Down Expand Up @@ -129,6 +130,34 @@ int main (int argc, char * argv[]) {
exit(1);
}

if(!dp.gui){

atcoord * ac = ((atcoords *)ent)->m[dp.n];
if(dp.b>0 && !ac->bond_flag){
bonds_fill(dp.rl, ac);
}

int c;
while((c = getc(stdin))!=EOF){
switch(c){
case('p'):
kp_print2fig(ent, &dp); break;
case('z'):
kp_print_xyz(ent, &dp); break;
case('x'):
kp_print(ent, &dp); break;
case('.'):
{
styp sym;
pg(ac, sym, dp.symtol);
printf("%s\n", sym);
}; break;
}
}
ent_free(ent, &dp);
exit(0);
}

/*= X11 init ===============================================================*/
ptf kp[NKP];
init_x(dp.fname);
Expand Down
3 changes: 2 additions & 1 deletion src/v/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ int cli_parse(char * arg, drawpars * dp){
int a3 = sscanf (arg, "bonds:%d", &bonds);
int a4 = sscanf (arg, "z:%d,%d,%d,%d,%d", dp->z, dp->z+1, dp->z+2, dp->z+3, dp->z+4);
int a5 = sscanf (arg, "font:%255s", dp->fontname);
int a6 = sscanf (arg, "gui:%d", &(dp->gui));
int a7 = sscanf (arg, "bohr:%d", &(dp->bohr));
int rot_count = sscan_rot (arg, rot);
int cell_count = sscan_cell (arg, cell);
int shell_count = sscan_shell(arg, shell);

int cli = a0||a1||a2||a3||a4||a5||a7 || rot_count||cell_count||shell_count;
int cli = a0||a1||a2||a3||a4||a5||a6||a7 || rot_count||cell_count||shell_count;

if(vib==0){
dp->task = AT3COORDS;
Expand Down
12 changes: 1 addition & 11 deletions src/v/evr.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,7 @@ void kp_move_d(void * ent, drawpars * dp){
}

void kp_exit(void * ent, drawpars * dp){
if (dp->task == VIBRO){
free(((vibrstr *)ent)->ac);
free(((vibrstr *)ent)->modes);
free(ent);
}
else if (dp->task == AT3COORDS){
if(dp->f){
fclose(dp->f);
}
acs_free(ent);
}
ent_free(ent, dp);
close_x();
exit(0);
}
Expand Down
1 change: 1 addition & 0 deletions src/v/man.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ printf("\
cell:%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf,%%lf cell parameters in Å \n\
shell:b%%lf,%%lf spheres radii in a.u. \n\
shell:%%lf,%%lf spheres radii in Å \n\
gui:%%d` normal (1) / headless (0) mode\n\
\n\
KEYBOARD REFERENCE:\n\
\n\
Expand Down
15 changes: 15 additions & 0 deletions src/v/tools.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
#include "v.h"
#include "sym.h"

void ent_free(void * ent, drawpars * dp){
if (dp->task == VIBRO){
free(((vibrstr *)ent)->ac);
free(((vibrstr *)ent)->modes);
free(ent);
}
else if (dp->task == AT3COORDS){
if(dp->f){
fclose(dp->f);
}
acs_free(ent);
}
return;
}

void acs_free(atcoords * acs){
for(int i=0; i<acs->n; i++){
free(acs->m[i]);
Expand Down
2 changes: 2 additions & 0 deletions src/v/v.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef struct {
task_t task; // data type
unsigned int dt; // animation timeout
char fontname[STRLEN];// font
int gui; //

double xy0[2]; // translation vector
double ac3rmx[9]; // rotational matrix
Expand Down Expand Up @@ -140,6 +141,7 @@ void drawshell (double rmin, double rmax, double scale, double * xy0);
int savepic (char * s);

// tools.c
void ent_free(void * ent, drawpars * dp);
void acs_free(atcoords * acs);
void newmol_prep(atcoords * acs, drawpars * dp);
void ac3_text(atcoord * ac, drawpars * dp);
Expand Down

0 comments on commit f7fee1c

Please sign in to comment.