def make_sander_input_file(parms): lines = [] lines.append("amber.py generated sander input file") lines.append("&cntrl") if parms['shake_on']: lines.append(" ntf = 2, ntb = $periodic, cut = $cutoff,") else: lines.append(" ntf = 1, ntb = $periodic, cut = $cutoff,") lines.append(" igb = $solvent_state, gbsa = $surface_area, nrespa = 1,") if parms['shake_on']: lines.append(" ntc = 2, tol = 1.0d-8,") else: lines.append(" ntc = 1") if parms['constraint_pdb']: lines.append(" ntr = 1") if 'n_step_minimization' in parms: lines.append(" imin = 1, nmropt = 0,") lines.append(" ntmin = 1, maxcyc = $n_step_minimization, ncyc = $n_step_steepest_descent,") elif 'n_step_dynamics' in parms: if parms['input_crds'].endswith('.rst'): lines.append(" ntx = 5, irest = 1,") else: lines.append(" ntx = 1,") lines.append(" ntpr = 50, ntave = 0, ntwr = 500, iwrap = 0, ioutfm = 0, " "ntwx = $n_step_per_snapshot, ntwv = $n_step_per_snapshot, " "ntwe = $n_step_per_snapshot, ") lines.append(" nstlim = $n_step_dynamics, nscm = 50, dt = 0.001,") if parms['periodic'] == 2: lines.append(" ntp = 1,") if 'thermometer_type' in parms: lines.append(" ntt = $thermometer_type, ig = $random_seed, " + \ "temp0 = $temp_thermometer, tempi = $temp_initial, vlimit = 0.0, ") if parms['thermometer_type'] == 2: lines.append(" vrand = $steps_per_thermostat, ") elif parms['thermometer_type'] == 3: lines.append(" gamma_ln = $gamma_ln, ") else: raise "Can't parse parameters to run " lines.append("/") if parms['constraint_pdb']: lines.append("Restrained atoms from %s" % parms['constraint_pdb']) restraint_weight = 20.0 lines.append(str(restraint_weight)) lines.append("FIND") lines.append("* * S *") lines.append("* * B *") lines.append("* * 3 *") lines.append("* * E *") lines.append("SEARCH") mol = pdbstruct.Molecule() mol.read_pdb(parms['constraint_pdb']) for i, atom in enumerate(mol.atoms()): if atom.bfactor > 0.0: lines.append("ATOM %d %d" % (i+1, i+1)) lines.append("END") lines.append("END") return util.replace_dict("\n".join(lines), parms)
def make_namd_input_file(parms): lines = [] lines.append("# initial structure and coordinates") lines.append("structure $topology") lines.append("coordinates $input_crds") lines.append("") lines.append("# output") lines.append("outputName $output_name") lines.append("binaryOutput no") lines.append("") lines.extend(force_field_template.splitlines()) if 'constraint_pdb' in parms: if parms['constraint_pdb']: lines.extend(_constraint_template.splitlines()) if 'n_step_dynamics' in parms: lines.append("# initial temperature/velocities") if 'input_vels' in parms and parms['input_vels'] <> "": lines.append("velocities $input_vels") elif 'temp_thermometer' in parms: lines.append("temperature $temp_thermometer") lines.append("seed $random_seed") elif 'temp_init' in parms: lines.append("temperature $temp_init") lines.append("seed $random_seed") else: raise IndexError, "No initial velocity information for dynamics run" if 'n_step_dynamics' in parms: lines.extend(md_template.splitlines()) else: lines.append("# minimization parameters") lines.append("minimization on") if 'temp_thermometer' in parms: lines.append("# temperature coupling") lines.append("langevin on") lines.append("langevinHydrogen on") if 'temp_couple' in parms: lines.append("langevinTemp $temp_couple") lines.append("langevinFile $couple_pdb") lines.append("langevinCol B") else: lines.append("langevinTemp $temp_thermometer") lines.append("langevinDamping 10.0") return util.replace_dict("\n".join(lines), parms)
def make_namd_from_pdb(pdb, psf, out_pdb): """ Creates charmm .pdb and .psf file. Can only make NAMD generate CHARMM topology files, not OPLS ones - that requires XPLOR but I don't care. Still, if OPLS topology files are provided - can still run. """ def is_non_water_hetatm(line): if not line.startswith("HETATM"): return False if line[17:20] != 'HOH': return True return False in_pdb = util.temp_fname('.pdb') txt = open(pdb, 'r').read() txt = pdbtext.strip_other_nmr_models(txt) txt = pdbtext.strip_lines(txt, is_non_water_hetatm) txt = pdbtext.strip_lines(txt, lambda l: l.startswith('ANISOU')) txt = pdbtext.strip_lines(txt, lambda l: l.startswith('CONECT')) txt = pdbtext.strip_lines(txt, lambda l: l.startswith('MASTER')) txt = pdbtext.strip_alternative_atoms(txt) txt = pdbtext.strip_hydrogens(txt) txt = pdbtext.renumber_residues(txt) f = open(in_pdb, 'w') f.write(txt) f.close() name = psf.replace('.psf', '') psfgen_in = name + ".psfgen.in" psfgen_out = name + ".psfgen.out" replace = { 'pdb': in_pdb, 'out_pdb': out_pdb, 'psf': psf, 'module_dir': module_dir, 'topology': 'parms/charmm22.topology' } template = _psfgen_template soup = Soup(in_pdb) chains = soup.chains() water_names = ['WAT', "TIP", "TIP3", "HOH"] waters = [chain for chain in chains if chain.n_residue() > 0 and chain.residue(0).type in water_names] chains = [chain for chain in chains if chain.n_residue() > 0 and chain.residue(0).type not in water_names] if len(waters) > 0: template = template.replace("# insert water", _water_psfgen_template) water_pdb = name + ".waters.pdb" water_soup = Soup() for water in waters: water_soup.insert_chain(water) water_soup.write_pdb(water_pdb) replace['water_pdb'] = water_pdb chains_template = "" for i, chain in enumerate(chains): id = 'ch%d' % i pdb = name + '.' + id + '.pdb' chain_soup = Soup() chain_soup.append_chain(chain) chain_soup.write_pdb(pdb) chain_replace = { 'chain_id': id, 'chain_pdb': pdb } chain_template = _chain_psfgen_template chains_template += util.replace_dict(chain_template, chain_replace) template = template.replace("# insert protein", chains_template) template = util.replace_dict(template, replace) open(psfgen_in, "w").write(template) os.system("psfgen %s > %s" % (psfgen_in, psfgen_out)) os.remove(in_pdb)
mol selection {backbone} mol representation NewCartoon 0.40 20.00 2.50 0 mol addrep top mol selection {all} mol representation CPK 0.5 2 8 6 mol addrep top mol smoothrep top 0 2 mol smoothrep top 1 2 """ if len(sys.argv) < 2: print "Usage: vmdtraj.py md" sys.exit(1) in_md = sys.argv[1] parms = {"ext_top": "parm7", "ext_trj": "crd", "top": in_md + ".top", "trj": in_md + ".trj"} if not has_files(parms["top"], parms["trj"]): parms = {"ext_top": "gro", "ext_trj": "trr", "top": in_md + ".gro", "trj": in_md + ".trr"} if not has_files(parms["top"], parms["trj"]): parms = {"ext_top": "psf", "ext_trj": "dcd", "top": in_md + ".psf", "trj": in_md + ".dcd"} if not has_files(parms["top"], parms["trj"]): print "Can't recognize trajectories with basename", in_md cmd_fname = util.temp_fname(".vmd") script = util.replace_dict(s, parms) open(cmd_fname, "w").write(script) os.system(vmd + " -e " + cmd_fname) os.remove(cmd_fname)