/*------------------------------------------------------------*/ void select_residue_model (void) { mol3d *mol; res3d *res; int *flags; int flag, model; #ifndef NDEBUG int old = count_residue_selections(); #endif assert (dstack_size == 1); model = ival; clear_dstack(); push_residue_selection(); flags = current_residue_sel->flags; for (mol = first_molecule; mol; mol = mol->next) { flag = mol->model == model; for (res = mol->first; res; res = res->next) *flags++ = flag; } #ifdef SELECT_DEBUG fprintf (stderr, "residue select model: %i\n", select_residue_count()); #endif #ifndef NDEBUG assert (count_residue_selections() == old + 1); #endif }
/*------------------------------------------------------------*/ void select_atom_sphere (void) { mol3d *mol; res3d *res; at3d *at; vector3 centre; double sqradius; int *flags; #ifndef NDEBUG int old = count_atom_selections(); #endif assert (dstack_size == 4); centre.x = dstack[0]; centre.y = dstack[1]; centre.z = dstack[2]; sqradius = dstack[3]; clear_dstack(); if (sqradius < 0.0) { yyerror ("invalid radius value"); return; } sqradius *= sqradius; push_atom_selection(); flags = current_atom_sel->flags; for (mol = first_molecule; mol; mol = mol->next) { for (res = mol->first; res; res = res->next) { for (at = res->first; at; at = at->next) { *flags++ = v3_close (&(at->xyz), ¢re, sqradius); } } } #ifdef SELECT_DEBUG fprintf (stderr, "atom select sphere: %i\n", select_atom_count()); #endif #ifndef NDEBUG assert (count_atom_selections() == old + 1); #endif }
/*------------------------------------------------------------*/ void select_atom_b_factor (void) { mol3d *mol; res3d *res; at3d *at; double lower, upper; int *flags; #ifndef NDEBUG int old = count_atom_selections(); #endif assert (dstack_size == 2); lower = dstack[0]; upper = dstack[1]; clear_dstack(); if (upper < lower) { yyerror ("invalid b-factor range values"); return; } push_atom_selection(); flags = current_atom_sel->flags; for (mol = first_molecule; mol; mol = mol->next) { for (res = mol->first; res; res = res->next) { for (at = res->first; at; at = at->next) { *flags++ = ((lower <= at->bfactor) && (at->bfactor <= upper)); } } } #ifdef SELECT_DEBUG fprintf (stderr, "atom select b-factor: %i\n", select_atom_count()); #endif #ifndef NDEBUG assert (count_atom_selections() == old + 1); #endif }
/*------------------------------------------------------------*/ void select_atom_close (void) { double sqdistance; int slot, atom_count; int *flags; #ifndef NDEBUG int old = count_atom_selections(); #endif assert (dstack_size == 1); sqdistance = dstack[0]; clear_dstack(); if (sqdistance < 0.0) { yyerror ("invalid distance value"); return; } sqdistance *= sqdistance; atom_count = select_atom_count(); if (atom_count == 0) { flags = current_atom_sel->flags; for (slot = 0; slot < total_atoms; slot++) *flags++ = FALSE; } else { mol3d *mol; res3d *res; at3d *at; int flag; at3d **atoms, **close_atoms; close_atoms = malloc (atom_count * sizeof (at3d *)); atoms = close_atoms; flags = current_atom_sel->flags; for (mol = first_molecule; mol; mol = mol->next) { for (res = mol->first; res; res = res->next) { for (at = res->first; at; at = at->next) { if (*flags++) *atoms++ = at; } } } select_atom_not(); push_atom_selection(); flags = current_atom_sel->flags; for (mol = first_molecule; mol; mol = mol->next) { for (res = mol->first; res; res = res->next) { for (at = res->first; at; at = at->next) { flag = FALSE; atoms = close_atoms; for (slot = 0; slot < atom_count; slot++, atoms++) { if (v3_close (&(at->xyz), &((*atoms)->xyz), sqdistance)) { flag = TRUE; break; } } *flags++ = flag; } } } select_atom_and(); free (close_atoms); } #ifdef SELECT_DEBUG fprintf (stderr, "atom select close: %i\n", select_atom_count()); #endif #ifndef NDEBUG assert (count_atom_selections() == old); #endif }
double stack_eval(double t, double *c_in, double *x_in, D_Stack *d_stack, StackExpr expr ) { // I_Stack *serial = new_istack(); // I_Stack istack; // I_Stack *serial = &istack; clear_dstack(d_stack); int* serial = expr.serial; #ifdef print_stack_eval printf("Serial: |%d|", expr.s_len); #endif int s; for( s=0; s < expr.s_len; s++ ) { // #ifdef print_stack_eval // printf( "%d ", expr.serial[s]); // #endif // push_istack(serial,expr.serial[expr.s_len-s-1]); // } // #ifdef print_stack_eval // printf("\n"); // #endif // clear_dstack(d_stack); // // fill i_stack with cmds and d_stack with leaves // while ( !is_empty_istack(serial) ) { // // printf( "processing serial\n"); // int val = top_istack(serial); // pop_istack(serial); int val = serial[s]; #ifdef print_stack_eval int dlen = len_dstack(d_stack); int slen = len_istack(serial); printf( "S: %d val: %d \n", slen, val ); printf( "serial(%d): [ ", slen); for( i=0; i < slen; i++ ) printf( "%d ", get_istack(serial,i) ); printf(" ]\n"); printf( "d_stack(%d): [ ", dlen); for( i=0; i < dlen; i++ ) printf( "%.2f ", get_dstack(d_stack,i) ); printf(" ]\n"); #endif switch (val) { // CONSTANT: 2 case 2: { s++; int p = serial[s]; // int p = top_istack(serial); // pop_istack(serial); push_dstack(d_stack,c_in[p]); } break; // HACK*** // CONSTANTF: 3 case 3: { s++; int p = serial[s]; // int p = top_istack(serial); // pop_istack(serial); push_dstack(d_stack,p); } break; // TIME: 4 case 4: push_dstack(d_stack,t); break; // SYSTEM: 5 // case 5: // s++; // push_dstack(d_stack,sys_in[serial[s]]); // VAR: 6 should already be transformed, but just in case case 6: { s++; int p = serial[s]; // int p = top_istack(serial); // pop_istack(serial); push_dstack(d_stack,x_in[p]); break; } // NEG: 9 case 9: { double top = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, -top); } break; // ABS: 10 case 10: { double top = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, fabs(top)); } break; // SQRT: 11 case 11: { double top = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, sqrt(top)); } break; // SIN: 12 case 12: { double top = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, sin(top)); } break; // COS: 13 case 13: { double top = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, cos(top)); } break; // TAN: 14 case 14: { double top = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, tan(top)); } break; // EXP: 15 case 15: { double top = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, exp(top)); } break; // LOG: 16 case 16: { double top = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, log(top)); } break; // POWI: 18 case 18: { double top = top_dstack(d_stack); pop_dstack(d_stack); s++; int pwr = serial[s]; // int pwr = top_istack(serial); // pop_istack(serial); push_dstack(d_stack, pow(top,pwr)); } break; // POWE: 20 case 20: { double top = top_dstack(d_stack); pop_dstack(d_stack); double pwr = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, pow(top,pwr)); } break; // DIV: 21 case 21: { double denom = top_dstack(d_stack); pop_dstack(d_stack); double numer = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, numer / denom); } break; // ADD: 22 case 22: { double lhs = top_dstack(d_stack); pop_dstack(d_stack); double rhs = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, lhs + rhs); // printf( "%f + %f = %f\n", lhs, rhs, top_dstack(d_stack)); } break; // MUL: 23 case 23: { double lhs = top_dstack(d_stack); pop_dstack(d_stack); double rhs = top_dstack(d_stack); pop_dstack(d_stack); push_dstack(d_stack, lhs * rhs); // printf( "%f * %f = %f\n", lhs, rhs, top_dstack(d_stack)); } break; case 0: default: // STARTVAR: 25 if (val >= 25) { push_dstack(d_stack,x_in[val-25]); // x_dim_of_var = val - STARTVAR } else { printf("pushing unknown cmd %d\n", val); int s; for( s=0; s < expr.s_len; s++ ) { printf( "%d ", expr.serial[s]); } printf( "\n"); abort(); } } #ifdef print_stack_eval dlen = len_dstack(d_stack); printf( "S: %d val: %d\n", s, val); printf( "d_stack(%d): [ ", dlen); for( i=0; i < dlen; i++ ) printf( "%.2f ", get_dstack(d_stack,i) ); printf(" ]\n\n"); #endif } // free(serial); return top_dstack(d_stack); }