static void add_lj_interaction(PdbParser::PdbParser &parser, std::vector<PdbLJInteraction> interactions, const double rel_cutoff, const int first_type) { for(std::vector<PdbLJInteraction>::const_iterator it = interactions.begin(); it != interactions.end(); ++it) { for(std::map<std::string, PdbParser::itp_atomtype>::const_iterator jt = parser.itp_atomtypes.begin(); jt != parser.itp_atomtypes.end(); ++jt) { const double epsilon_ij = sqrt(it->epsilon * jt->second.epsilon); const double sigma_ij = 0.5*(it->sigma+jt->second.epsilon); const double cutoff_ij = rel_cutoff*sigma_ij; const double shift_ij = -pow(sigma_ij/cutoff_ij,12) - pow(sigma_ij/cutoff_ij,6); READPDB_TRACE(printf("adding lj interaction types %d %d eps %e sig %e cut %e shift %e\n", it->other_type, first_type + jt->second.id, epsilon_ij, sigma_ij, cutoff_ij, shift_ij);); lennard_jones_set_params(it->other_type, first_type + jt->second.id, epsilon_ij, sigma_ij, cutoff_ij, shift_ij, 0.0, -1.0, 0.0); } }
int tclcommand_inter_parse_lj(Tcl_Interp * interp, int part_type_a, int part_type_b, int argc, char ** argv) { /* parameters needed for LJ */ double eps, sig, cut, shift, offset, cap_radius, min; int compute_auto_shift, change; /* get lennard-jones interaction type */ if (argc < 4) { Tcl_AppendResult(interp, "lennard-jones needs at least 3 parameters: " "<lj_eps> <lj_sig> <lj_cut> [<lj_shift> [<lj_offset> [<lj_cap> [<lj_min>]]]]", (char *) NULL); return 0; } change = 1; /* PARSE LENNARD-JONES COMMAND LINE */ /* epsilon */ if (! ARG_IS_D(1, eps)) { Tcl_AppendResult(interp, "<lj_eps> should be a double", (char *) NULL); return 0; } change++; /* sigma */ if (! ARG_IS_D(2, sig)) { Tcl_AppendResult(interp, "<lj_sig> should be a double", (char *) NULL); return 0; } change++; /* cutoff */ if (! ARG_IS_D(3, cut)) { Tcl_AppendResult(interp, "<lj_cut> should be a double", (char *) NULL); return 0; } change++; /* shift */ if (argc > 4) { if (ARG_IS_D(4, shift)) { /* if a shift is given, use that one */ compute_auto_shift = 0; change++; } else if (ARG_IS_S(4, "auto")) { Tcl_ResetResult(interp); compute_auto_shift = 1; /* if shift is "auto", autocompute the shift */ change++; } else { Tcl_AppendResult(interp, "<lj_shift> should be a double or \"auto\"", (char *) NULL); return 0; } } else { /* by default, compute the shift automatically */ compute_auto_shift = 1; } /* the shift can be computed automatically only when the other parameters have been determined, see below */ /* offset */ if (argc > 5) { if (!ARG_IS_D(5, offset)) { Tcl_AppendResult(interp, "<lj_off> should be a double", (char *) NULL); return 0; } change++; } else { offset = 0.0; } /* cap_radius */ if (argc > 6) { if (!ARG_IS_D(6, cap_radius)) { Tcl_AppendResult(interp, "<lj_cap> should be a double", (char *) NULL); return 0; } change++; } else { cap_radius = -1.0; } /* minimal radius */ if (argc > 7) { if (!ARG_IS_D(7, min)) { Tcl_AppendResult(interp, "<lj_rmin> should be a double", (char *) NULL); return 0; } change ++; } else { min = 0.0; } /* automatically compute the shift */ if (compute_auto_shift) shift = -(pow(sig/cut, 12) - pow(sig/cut, 6)); /* now set the parameters */ if (lennard_jones_set_params(part_type_a, part_type_b, eps, sig, cut, shift, offset, cap_radius, min) == ES_ERROR) { Tcl_AppendResult(interp, "particle types must be non-negative", (char *) NULL); return 0; } return change; }