def pdb_to_top_and_crds(force_field, pdb, basename, solvent_buffer=10): """ Converts a PDB file into GROMACS topology and coordinate files, and fully converted PDB file. These constitute the restart files of a GROMACS simulation. """ util.check_files(pdb) full_pdb = os.path.abspath(pdb) save_dir = os.getcwd() # All intermediate files placed into a subdirectory util.goto_dir(basename + '.solvate') # Remove all but protein heavy atoms in a single clean conformation pdb = basename + '.clean.pdb' pdbtext.clean_pdb(full_pdb, pdb) # Generate protein topology in pdb2gmx_gro using pdb2gmx pdb2gmx_gro = basename + '.pdb2gmx.gro' top = basename + '.top' itp = basename + '_posre.itp' # Choose force field based on GROMACS version if 'GROMACS4.5' in force_field: ff = 'amber99' elif 'GROMACS4.0' in force_field: ff = 'G43a1' else: raise ValueError, "Couldn't work out pdb2gmx for " + force_field args = '-ignh -ff %s -water spc -missing -f %s -o %s -p %s -i %s -chainsep id_or_ter -merge all' \ % (ff, pdb, pdb2gmx_gro, top, itp) data.binary('pdb2gmx', args, basename + '.pdb2gmx') util.check_files(pdb2gmx_gro) # Now add a box with editconf box_gro = basename + '.box.gro' solvent_buffer_in_nm = solvent_buffer / 10.0 data.binary( 'editconf', '-f %s -o %s -c -d %f -bt cubic' \ % (pdb2gmx_gro, box_gro, solvent_buffer_in_nm), basename+'.box') util.check_files(box_gro) # Given box dimensions, can now populate with explict waters solvated_gro = basename + '.solvated.gro' data.binary( 'genbox', '-cp %s -cs spc216.gro -o %s -p %s' \ % (box_gro, solvated_gro, top), '%s.solvated' % basename) util.check_files(solvated_gro) # Neutralize with counterions using genion to place ions # based on energy parameters processed by grompp gro = basename + '.gro' neutralize_system_with_salt(top, solvated_gro, basename, force_field) util.check_files(gro) # Make a reference PDB file from restart files for viewing and restraints convert_restart_to_pdb(basename, basename + '.pdb') # Copy finished restart files back into original directory fnames = util.re_glob( '*', os.path.basename(basename) + r'[^\.]*\.(pdb|itp|gro|mdp|top)$') for fname in fnames: shutil.copy(fname, save_dir) # Cleanup delete_backup_files(basename) os.chdir(save_dir) return top, gro
def pdb_to_top_and_crds(force_field, pdb, basename, solvent_buffer=10): """ Converts a PDB file into GROMACS topology and coordinate files, and fully converted PDB file. These constitute the restart files of a GROMACS simulation. """ util.check_files(pdb) full_pdb = os.path.abspath(pdb) save_dir = os.getcwd() # All intermediate files placed into a subdirectory util.goto_dir(basename + '.solvate') # Remove all but protein heavy atoms in a single clean conformation pdb = basename + '.clean.pdb' pdbtext.clean_pdb(full_pdb, pdb) # Generate protein topology in pdb2gmx_gro using pdb2gmx pdb2gmx_gro = basename + '.pdb2gmx.gro' top = basename + '.top' itp = basename + '_posre.itp' # Choose force field based on GROMACS version if 'GROMACS4.5' in force_field: ff = 'amber99' elif 'GROMACS4.0' in force_field: ff = 'G43a1' else: raise ValueError, "Couldn't work out pdb2gmx for " + force_field args = '-ignh -ff %s -water spc -missing -f %s -o %s -p %s -i %s -chainsep id_or_ter -merge all' \ % (ff, pdb, pdb2gmx_gro, top, itp) data.binary('pdb2gmx', args, basename+'.pdb2gmx') util.check_files(pdb2gmx_gro) # Now add a box with editconf box_gro = basename + '.box.gro' solvent_buffer_in_nm = solvent_buffer/10.0 data.binary( 'editconf', '-f %s -o %s -c -d %f -bt cubic' \ % (pdb2gmx_gro, box_gro, solvent_buffer_in_nm), basename+'.box') util.check_files(box_gro) # Given box dimensions, can now populate with explict waters solvated_gro = basename + '.solvated.gro' data.binary( 'genbox', '-cp %s -cs spc216.gro -o %s -p %s' \ % (box_gro, solvated_gro, top), '%s.solvated' % basename) util.check_files(solvated_gro) # Neutralize with counterions using genion to place ions # based on energy parameters processed by grompp gro = basename + '.gro' neutralize_system_with_salt(top, solvated_gro, basename, force_field) util.check_files(gro) # Make a reference PDB file from restart files for viewing and restraints convert_restart_to_pdb(basename, basename+'.pdb') # Copy finished restart files back into original directory fnames = util.re_glob( '*', os.path.basename(basename) + r'[^\.]*\.(pdb|itp|gro|mdp|top)$') for fname in fnames: shutil.copy(fname, save_dir) # Cleanup delete_backup_files(basename) os.chdir(save_dir) return top, gro
def delete_backup_files(tag): util.clean_fname(*util.re_glob('*', '^#' + tag))