int tclcommand_analyze_set_parse_trapmol(Tcl_Interp *interp, int argc, char **argv) { #ifdef MOLFORCES #ifdef EXTERNAL_FORCES int trap_flag = 0; int noforce_flag =0; int i; #endif #endif int mol_num; double spring_constant; double drag_constant; int isrelative; DoubleList trap_center; IntList trap_coords; IntList noforce_coords; char usage[] = "trapmol usage: <mol_id> { <xpos> <ypos> <zpos> } <isrelative> <spring_constant> <drag_constant> coords { <trapped_coord> <trapped_coord> <trapped_coord> } noforce_coords {<noforce_coord> <noforce_coord> <noforce_coord>}"; init_doublelist(&trap_center); init_intlist(&trap_coords); alloc_intlist(&trap_coords,3); init_intlist(&noforce_coords); alloc_intlist(&noforce_coords,3); /* Unless coords are specified the default is just to trap it completely */ trap_coords.e[0] = 1; trap_coords.e[1] = 1; trap_coords.e[2] = 1; Tcl_ResetResult(interp); /* The first argument should be a molecule number */ if (!ARG0_IS_I(mol_num)) { Tcl_AppendResult(interp, "first argument should be a molecule id", (char *)NULL); Tcl_AppendResult(interp, usage, (char *)NULL); return TCL_ERROR; } else { /* Sanity checks */ if (mol_num > n_molecules) { Tcl_AppendResult(interp, "trapmol: cannot trap mol %d because it does not exist",mol_num , (char *)NULL); return TCL_ERROR; } argc--; argv++; } /* The next argument should be a double list specifying the trap center */ if (!ARG0_IS_DOUBLELIST(trap_center)) { Tcl_AppendResult(interp, "second argument should be a double list", (char *)NULL); Tcl_AppendResult(interp, usage , (char *)NULL); return TCL_ERROR; } else { argc -= 1; argv += 1; } /* The next argument should be an integer specifying whether the trap is relative (fraction of box_l) or absolute */ if (!ARG0_IS_I(isrelative)) { Tcl_AppendResult(interp, "third argument should be an integer", (char *)NULL); Tcl_AppendResult(interp, usage, (char *)NULL); return TCL_ERROR; } else { argc -= 1; argv += 1; } /* The next argument should be the spring constant for the trap */ if (!ARG0_IS_D(spring_constant)) { Tcl_AppendResult(interp, "fourth argument should be a double", (char *)NULL); Tcl_AppendResult(interp, usage, (char *)NULL); return TCL_ERROR; } else { argc -= 1; argv += 1; } /* The next argument should be the drag constant for the trap */ if (!ARG0_IS_D(drag_constant)) { Tcl_AppendResult(interp, "fifth argument should be a double", (char *)NULL); Tcl_AppendResult(interp, usage, (char *)NULL); return TCL_ERROR; } else { argc -= 1; argv += 1; } /* Process optional arguments */ while ( argc > 0 ) { if ( ARG0_IS_S("coords") ) { if ( !ARG_IS_INTLIST(1,trap_coords) ) { Tcl_AppendResult(interp, "an intlist is required to specify coords", (char *)NULL); Tcl_AppendResult(interp, usage, (char *)NULL); return TCL_ERROR; } argc -= 2; argv += 2; } else if ( ARG0_IS_S("noforce_coords")) { if ( !ARG_IS_INTLIST(1,noforce_coords) ) { Tcl_AppendResult(interp, "an intlist is required to specify coords", (char *)NULL); Tcl_AppendResult(interp, usage, (char *)NULL); return TCL_ERROR; } argc -= 2; argv += 2; } else { Tcl_AppendResult(interp, "an option is not recognised", (char *)NULL); Tcl_AppendResult(interp, usage, (char *)NULL); return TCL_ERROR; } } #ifdef MOLFORCES #ifdef EXTERNAL_FORCES for (i = 0; i < 3; i++) { if (trap_coords.e[i]) trap_flag |= COORD_FIXED(i); if (noforce_coords.e[i]) noforce_flag |= COORD_FIXED(i); } if (set_molecule_trap(mol_num, trap_flag,&trap_center,spring_constant, drag_constant, noforce_flag, isrelative) == TCL_ERROR) { Tcl_AppendResult(interp, "set topology first", (char *)NULL); return TCL_ERROR; } #else Tcl_AppendResult(interp, "Error: EXTERNAL_FORCES not defined ", (char *)NULL); return TCL_ERROR; #endif #endif realloc_doublelist(&trap_center,0); realloc_intlist(&trap_coords,0); realloc_intlist(&noforce_coords,0); return tclcommand_analyze_set_parse_topo_part_sync(interp); }
int tabulated_set_params(int part_type_a, int part_type_b, char* filename) { IA_parameters *data; FILE* fp; int npoints; double minval, maxval; int i, newsize; int token; double dummr; token = 0; data = get_ia_param_safe(part_type_a, part_type_b); if (!data) return 1; if (strlen(filename) > MAXLENGTH_TABFILE_NAME-1 ) return 2; /* Open the file containing force and energy tables */ fp = fopen( filename , "r"); if ( !fp ) return 3; /* Look for a line starting with # */ while ( token != EOF) { token = fgetc(fp); if ( token == '#' ) { break; } } if ( token == EOF ) { fclose(fp); return 4; } /* First read two important parameters we read in the data later*/ if (fscanf( fp , "%d %lf %lf", &npoints, &minval, &maxval) != 3) return 5; // Set the newsize to the same as old size : only changed if a new force table is being added. newsize = tabulated_forces.max; if ( data->TAB_npoints == 0){ // A new potential will be added so set the number of points, the startindex and newsize data->TAB_npoints = npoints; data->TAB_startindex = tabulated_forces.max; newsize += npoints; } else { // We have existing data for this pair of monomer types check array sizing if ( data->TAB_npoints != npoints ) { fclose(fp); return 6; } } /* Update parameters symmetrically */ data->TAB_maxval = maxval; data->TAB_minval = minval; strcpy(data->TAB_filename,filename); /* Calculate dependent parameters */ data->TAB_stepsize = (maxval-minval)/(double)(data->TAB_npoints - 1); /* Allocate space for new data */ realloc_doublelist(&tabulated_forces,newsize); realloc_doublelist(&tabulated_energies,newsize); /* Read in the new force and energy table data */ for (i =0 ; i < npoints ; i++) { if (fscanf(fp,"%lf %lf %lf",&dummr, &(tabulated_forces.e[i+data->TAB_startindex]), &(tabulated_energies.e[i+data->TAB_startindex])) != 3) return 5; } fclose(fp); /* broadcast interaction parameters including force and energy tables*/ mpi_bcast_ia_params(part_type_a, part_type_b); mpi_cap_forces(force_cap); return 0; }