def launch(self): """Launches the execution of the GNUPLOT binary. """ out_log, err_log = fu.get_logs(path=self.path, mutation=self.mutation, step=self.step) self.output_plotscript_path = fu.add_step_mutation_path_to_name(self.output_plotscript_path, self.step, self.mutation) # Create the input script for gnuplot xvg_file_list = [] with open(self.output_plotscript_path, 'w') as ps: ps.write('set term '+self.term+'\n') ps.write('set output "' + self.output_png_path + '"'+'\n') ps.write('plot') for k, v in self.input_xvg_path_dict.iteritems(): if isinstance(v, basestring) and os.path.isfile(v): ps.write(' "' + v + '" u 1:3 w lp t "' + k + '",') else: xvg_file = fu.add_step_mutation_path_to_name(k + '.xvg', self.step, self.mutation) np.savetxt(xvg_file, v, fmt='%4.7f') out_log.info('Creating file: '+os.path.abspath(xvg_file)) xvg_file_list.append(os.path.abspath(xvg_file)) ps.write(' "' + xvg_file + '" u 0:2 w lp t "' + k + '", ') gplot = 'gnuplot' if self.gnuplot_path is None else self.gnuplot_path cmd = [gplot, self.output_plotscript_path] command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log) returncode = command.launch() return returncode
def launch(self): """Launches the execution of the GROMACS solvate module. """ out_log, err_log = fu.get_logs(path=self.path, mutation=self.mutation, step=self.step) self.output_top_path = fu.add_step_mutation_path_to_name(self.output_top_path, self.step, self.mutation) # Unzip topology to topology_out fu.unzip_top(zip_file=self.input_top_zip_path, top_file=self.output_top_path) gmx = 'gmx' if self.gmx_path is None else self.gmx_path cmd = [gmx, 'solvate', '-cp', self.input_solute_gro_path, '-cs', self.input_solvent_gro_path, '-o', self.output_gro_path, '-p', self.output_top_path] if self.mpirun_np is not None: cmd.insert(0, str(self.mpirun_np)) cmd.insert(0, '-np') if self.mpirun: cmd.insert(0, 'mpirun') command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log) returncode = command.launch() with open(self.output_top_path) as topology_file: out_log.info('Last 5 lines of new top file: ') lines = topology_file.readlines() for index in [-i for i in range(5,0,-1)]: out_log.info(lines[index]) # zip new_topology fu.zip_top(self.output_top_path, self.output_top_zip_path, remove_files=True) return returncode
def launch(self): """Launches the execution of the GROMACS genion module. """ if self.global_log is not None: if self.concentration: self.global_log.info(19 * ' ' + 'To reach up ' + str(self.concentration) + ' mol/litre concentration') out_log, err_log = fu.get_logs(path=self.path, mutation=self.mutation, step=self.step) self.output_top_path = fu.add_step_mutation_path_to_name( self.output_top_path, self.step, self.mutation) # Unzip topology to topology_out fu.unzip_top(zip_file=self.input_top_zip_path, top_file=self.output_top_path) gmx = 'gmx' if self.gmx_path is None else self.gmx_path cmd = [ gmx, 'genion', '-s', self.input_tpr_path, '-o', self.output_gro_path, '-p', self.output_top_path ] if self.mpirun_np is not None: cmd.insert(0, str(self.mpirun_np)) cmd.insert(0, '-np') if self.mpirun: cmd.insert(0, 'mpirun') if self.neutral: cmd.append('-neutral') if self.concentration: cmd.append('-conc') cmd.append(str(self.concentration)) if self.seed is not None: cmd.append('-seed') cmd.append(str(self.seed)) if self.mpirun: cmd.append('<<<') cmd.append('\"' + self.replaced_group + '\"') else: cmd.insert(0, '|') cmd.insert(0, '\"' + self.replaced_group + '\"') cmd.insert(0, 'echo') command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log) returncode = command.launch() # zip new_topology fu.zip_top(self.output_top_path, self.output_top_zip_path, remove_files=True) return returncode
def launch(self): """Launches the execution of the GROMACS pdb2gmx module. """ out_log, err_log = fu.get_logs(path=self.path, mutation=self.mutation, step=self.step) self.output_top_path = fu.add_step_mutation_path_to_name( self.output_top_path, self.step, self.mutation) gmx = "gmx" if self.gmx_path is None else self.gmx_path cmd = [ gmx, "pdb2gmx", "-f", self.input_structure_pdb_path, "-o", self.output_gro_path, "-p", self.output_top_path, "-water", self.water_type, "-ff", self.force_field ] if self.mpirun_np is not None: cmd.insert(0, str(self.mpirun_np)) cmd.insert(0, '-np') if self.mpirun: cmd.insert(0, 'mpirun') if self.output_itp_path is not None: self.output_itp_path = self.output_itp_path if self.step is None else self.step + '_' + self.output_itp_path self.output_itp_path = self.output_itp_path if self.mutation is None else self.mutation + '_' + self.output_itp_path cmd.append("-i") cmd.append(self.output_itp_path) if self.ignh: cmd.append("-ignh") command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log) returncode = command.launch() #Remove comment (first line) from gro file with open(self.output_gro_path, 'r') as fin: data = fin.read().splitlines(True) data[0] = 'Created with pdb2gmx building block\n' with open(self.output_gro_path, 'w') as fout: fout.writelines(data) # zip topology fu.zip_top(self.output_top_path, self.output_top_zip_path, remove_files=True) return returncode
def launch(self): """Launches the execution of the GROMACS pdb2gmx module. """ out_log, err_log = fu.get_logs(path=self.path, mutation=self.mutation, step=self.step) self.output_top_path = fu.add_step_mutation_path_to_name( self.output_top_path, self.step, self.mutation) self.output_itp_path = fu.add_step_mutation_path_to_name( self.output_itp_path, self.step, self.mutation) gmx = "gmx" if self.gmx_path is None else self.gmx_path cmd = [ gmx, "genrestr", "-f", self.input_structure_path, "-n", self.input_ndx_path, "-o", self.output_itp_path, "-fc", self.force_constants ] if self.mpirun_np is not None: cmd.insert(0, str(self.mpirun_np)) cmd.insert(0, '-np') if self.mpirun: cmd.insert(0, 'mpirun') if self.mpirun: cmd.append('<<<') cmd.append('\"' + self.restricted_group + '\"') else: cmd.insert(0, '|') cmd.insert(0, '\"' + self.restricted_group + '\"') cmd.insert(0, 'echo') command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log) returncode = command.launch() fu.unzip_top(zip_file=self.input_top_zip_path, top_file=self.output_top_path) out_log.info('Unzip: ' + self.input_top_zip_path + ' to: ' + self.output_top_path) with open(self.output_top_path, 'r') as fin: for line in fin: if line.startswith('#ifdef POSRES'): itp_name = re.findall('"([^"]*)"', fin.next())[0] out_log.debug('itp_name: ' + itp_name) break # with open(self.output_top_path, 'r') as fin: # data = fin.read().splitlines(True) # index = data.index('#ifdef POSRES\n') # data[index+2] = 'system\n' # data.insert(index, '\n') # data.insert(index, '#endif\n') # data.insert(index, '#include "'+self.output_itp_path+'"\n') # data.insert(index, '#ifdef CUSTOM_POSRES\n') # data.insert(index, '; Include Position restraint file\n') # # data.insert(index, '#include "'+self.output_itp_path+'"\n') # # data.insert(index, '; Include genrestr generated itp\n') # with open(self.output_top_path, 'w') as fout: # fout.writelines(data) with open(self.output_itp_path, 'r') as fin: data = fin.read().splitlines(True) # data.insert(0, '\n') # data.insert(0, 'system 3\n') # data.insert(0, ';Name nrexcl\n') # data.insert(0, '[ system ]\n') with open(itp_name, 'w') as fout: fout.writelines(data) os.remove(self.output_itp_path) # zip topology fu.zip_top(self.output_top_path, self.output_top_zip_path, remove_files=False) out_log.info('Zip: ' + self.output_top_path + ' to: ' + self.output_top_zip_path) return returncode
def launch(self): """Launches the execution of the SCWRL binary. """ out_log, err_log = fu.get_logs(path=self.path, mutation=self.mutation, step=self.step) if self.mutation is not None: # Read structure with Biopython parser = PDBParser(PERMISSIVE=1, QUIET=True) st = parser.get_structure( 's', self.input_pdb_path) # s random id never used if self.mut_dict['chain'] != 'ALL': chains = [self.mut_dict['chain']] else: chains = [chain.id for chain in st[0]] resnum = int(self.mut_dict['resnum']) sequence = '' for chain in chains: residue = st[0][chain][(' ', resnum, ' ')] backbone_atoms = ['N', 'CA', 'C', 'O', 'CB'] not_backbone_atoms = [] # The following formula does not work. Biopython bug? # for atom in residue: # if atom.id not in backbone_atoms: # residue.detach_child(atom.id) for atom in residue: if atom.id not in backbone_atoms: not_backbone_atoms.append(atom) for atom in not_backbone_atoms: residue.detach_child(atom.id) # Change residue name residue.resname = self.mut_dict['mt'].upper() # Creating a sequence file where the lower case residues will # remain untouched and the upper case residues will be modified aa1c = { 'ALA': 'A', 'CYS': 'C', 'CYX': 'C', 'ASP': 'D', 'ASH': 'D', 'GLU': 'E', 'GLH': 'E', 'PHE': 'F', 'GLY': 'G', 'HIS': 'H', 'HID': 'H', 'HIE': 'H', 'HIP': 'H', 'ILE': 'I', 'LYS': 'K', 'LYP': 'K', 'LEU': 'L', 'MET': 'M', 'MSE': 'M', 'ASN': 'N', 'PRO': 'P', 'HYP': 'P', 'GLN': 'Q', 'ARG': 'R', 'SER': 'S', 'THR': 'T', 'VAL': 'V', 'TRP': 'W', 'TYR': 'Y' } for res in st[0][chain].get_residues(): if res.resname not in aa1c: st[0][chain].detach_child(res.id) elif (res.id == (' ', resnum, ' ')): sequence += aa1c[res.resname].upper() else: sequence += aa1c[res.resname].lower() # Write resultant sequence sequence_file_path = fu.add_step_mutation_path_to_name( "sequence.seq", self.step, self.mutation) with open(sequence_file_path, 'w') as sqfile: sqfile.write(sequence + "\n") # Write resultant structure w = PDBIO() w.set_structure(st) prepared_file_path = fu.add_step_mutation_path_to_name( "prepared.pdb", self.step, self.mutation) w.save(prepared_file_path) else: prepared_file_path = self.input_pdb_path scrwl = 'Scwrl4' if self.scwrl4_path is None else self.scwrl4_path cmd = [ scrwl, '-i', prepared_file_path, '-o', self.output_pdb_path, '-h', '-t' ] if self.mutation: cmd.append('-s') cmd.append(sequence_file_path) command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log) return command.launch()
def launch(self): """Launch the topology generation. """ out_log, err_log = fu.get_logs(path=self.path, mutation=self.mutation, step=self.step) self.output_top_path = fu.add_step_mutation_path_to_name( self.output_top_path, self.step, self.mutation) fu.unzip_top(zip_file=self.input_top_zip_path, top_file=self.output_top_path) out_log.info('Unzip: ' + self.input_top_zip_path + ' to: ' + self.output_top_path) # Create index list of index file :) index_dic = {} lines = open(self.input_ndx_path, 'r').read().splitlines() for index, line in enumerate(lines): if line.startswith('['): index_dic[line] = index, if index > 0: index_dic[label] = index_dic[label][0], index label = line index_dic[label] = index_dic[label][0], index out_log.info('Index_dic: ' + str(index_dic)) self.ref_rest_chain_triplet_list = [ tuple(elem.strip(' ()').replace(' ', '').split(',')) for elem in self.ref_rest_chain_triplet_list.split('),') ] for reference_group, restrain_group, chain in self.ref_rest_chain_triplet_list: out_log.info('Reference group: ' + reference_group) out_log.info('Restrain group: ' + restrain_group) out_log.info('Chain: ' + chain) self.output_itp_path = fu.add_step_mutation_path_to_name( restrain_group + '.itp', self.step, self.mutation) # Mapping atoms from absolute enumeration to Chain relative enumeration out_log.info('reference_group_index: start_closed:' + str(index_dic['[ ' + reference_group + ' ]'][0] + 1) + ' stop_open: ' + str(index_dic['[ ' + reference_group + ' ]'][1])) reference_group_list = [ int(elem) for line in lines[index_dic['[ ' + reference_group + ' ]'][0] + 1:index_dic['[ ' + reference_group + ' ]'][1]] for elem in line.split() ] out_log.info('restrain_group_index: start_closed:' + str(index_dic['[ ' + restrain_group + ' ]'][0] + 1) + ' stop_open: ' + str(index_dic['[ ' + restrain_group + ' ]'][1])) restrain_group_list = [ int(elem) for line in lines[index_dic['[ ' + restrain_group + ' ]'][0] + 1:index_dic['[ ' + restrain_group + ' ]'][1]] for elem in line.split() ] selected_list = [ reference_group_list.index(atom) + 1 for atom in restrain_group_list ] # Creating new ITP with restrictions with open(self.output_itp_path, 'w') as f: out_log.info('Creating: ' + str(f) + ' and adding the selected atoms force constants') f.write('[ position_restraints ]\n') f.write('; atom type fx fy fz\n') for atom in selected_list: f.write( str(atom) + ' 1 ' + self.force_constants + '\n') # Including new ITP in the corresponding ITP-chain file for file_name in os.listdir('.'): if not file_name.startswith( "posre") and not file_name.endswith("_pr.itp"): if fnmatch.fnmatch(file_name, "*_chain_" + chain + ".itp"): with open(file_name, 'a') as f: out_log.info( 'Opening: ' + str(f) + ' and adding the ifdef include statement') f.write('\n') f.write('; Include Position restraint file\n') f.write('#ifdef CUSTOM_POSRES\n') f.write('#include "' + self.output_itp_path + '"\n') f.write('#endif\n') # zip topology fu.zip_top(self.output_top_path, self.output_top_zip_path, remove_files=True) out_log.info('Zip: ' + self.output_top_path + ' to: ' + self.output_top_zip_path) return 0
def create_mdp(self): """Creates an MDP file using the properties file settings """ mdp_list=[] mdp_file_path=fu.add_step_mutation_path_to_name(self.output_mdp_path, self.step, self.mutation) sim_type = self.mdp.get('type', 'minimization') minimization = (sim_type == 'minimization') nvt = (sim_type == 'nvt') npt = (sim_type == 'npt') free = (sim_type == 'free') index = (sim_type == 'index') md = (nvt or npt or free) mdp_list.append(";Type of MDP: " + sim_type) # Position restrain if not free: mdp_list.append("\n;Position restrain") mdp_list.append("Define = " + self.mdp.pop('define', '-DPOSRES')) # Run parameters mdp_list.append("\n;Run parameters") self.nsteps= self.mdp.pop('nsteps', '5000') mdp_list.append("nsteps = " + self.nsteps) if minimization: mdp_list.append("integrator = " + self.mdp.pop('integrator', 'steep')) mdp_list.append("emtol = " + self.mdp.pop('emtol', '1000.0')) mdp_list.append("emstep = " + self.mdp.pop('emstep', '0.01')) if md: mdp_list.append("integrator = " + self.mdp.pop('integrator', 'md')) self.dt=self.mdp.pop('dt', '0.002') mdp_list.append("dt = " + self.dt) # Output control if md: mdp_list.append("\n;Output control") if nvt or npt: mdp_list.append("nstxout = " + self.mdp.pop('nstxout', '500')) mdp_list.append("nstvout = " + self.mdp.pop('nstvout', '500')) mdp_list.append("nstenergy = " + self.mdp.pop('nstenergy', '500')) mdp_list.append("nstlog = " + self.mdp.pop('nstlog', '500')) mdp_list.append("nstcalcenergy = " + self.mdp.pop('nstcalcenergy', '100')) mdp_list.append("nstcomm = " + self.mdp.pop('nstcomm', '100')) mdp_list.append("nstxout-compressed = " + self.mdp.pop('nstxout-compressed', '1000')) mdp_list.append("compressed-x-precision = " + self.mdp.pop('compressed-x-precision', '1000')) mdp_list.append("compressed-x-grps = " + self.mdp.pop('compressed-x-grps', 'System')) if free: mdp_list.append("nstcomm = " + self.mdp.pop('nstcomm', '100')) mdp_list.append("nstxout = " + self.mdp.pop('nstxout', '5000')) mdp_list.append("nstvout = " + self.mdp.pop('nstvout', '5000')) mdp_list.append("nstenergy = " + self.mdp.pop('nstenergy', '5000')) mdp_list.append("nstlog = " + self.mdp.pop('nstlog', '5000')) mdp_list.append("nstcalcenergy = " + self.mdp.pop('nstcalcenergy', '100')) mdp_list.append("nstxout-compressed = " + self.mdp.pop('nstxout-compressed', '1000')) mdp_list.append("compressed-x-grps = " + self.mdp.pop('compressed-x-grps', 'System')) mdp_list.append("compressed-x-precision = " + self.mdp.pop('compressed-x-precision', '1000')) # Bond parameters if md: mdp_list.append("\n;Bond parameters") mdp_list.append("constraint_algorithm = " + self.mdp.pop('constraint_algorithm', 'lincs')) mdp_list.append("constraints = " + self.mdp.pop('constraints', 'all-bonds')) mdp_list.append("lincs_iter = " + self.mdp.pop('lincs_iter', '1')) mdp_list.append("lincs_order = " + self.mdp.pop('lincs_order', '4')) if nvt: mdp_list.append("continuation = " + self.mdp.pop('continuation', 'no')) if npt or free: mdp_list.append("continuation = " + self.mdp.pop('continuation', 'yes')) # Neighbour searching mdp_list.append("\n;Neighbour searching") mdp_list.append("cutoff-scheme = " + self.mdp.pop('cutoff-scheme', 'Verlet')) mdp_list.append("ns_type = " + self.mdp.pop('ns_type', 'grid')) mdp_list.append("rcoulomb = " + self.mdp.pop('rcoulomb', '1.0')) mdp_list.append("vdwtype = " + self.mdp.pop('vdwtype', 'cut-off')) mdp_list.append("rvdw = " + self.mdp.pop('rvdw', '1.0')) mdp_list.append("nstlist = " + self.mdp.pop('nstlist', '10')) mdp_list.append("rlist = " + self.mdp.pop('rlist', '1')) # Eletrostatics mdp_list.append("\n;Eletrostatics") mdp_list.append("coulombtype = " + self.mdp.pop('coulombtype', 'PME')) if md: mdp_list.append("pme_order = " + self.mdp.pop('pme_order', '4')) mdp_list.append("fourierspacing = " + self.mdp.pop('fourierspacing', '0.12')) mdp_list.append("fourier_nx = " + self.mdp.pop('fourier_nx', '0')) mdp_list.append("fourier_ny = " + self.mdp.pop('fourier_ny', '0')) mdp_list.append("fourier_nz = " + self.mdp.pop('fourier_nz', '0')) mdp_list.append("ewald_rtol = " + self.mdp.pop('ewald_rtol', '1e-5')) # Temperature coupling if md: mdp_list.append("\n;Temperature coupling") mdp_list.append("tcoupl = " + self.mdp.pop('tcoupl', 'V-rescale')) mdp_list.append("tc-grps = " + self.mdp.pop('tc-grps', 'Protein Non-Protein')) mdp_list.append("tau_t = " + self.mdp.pop('tau_t', '0.1 0.1')) mdp_list.append("ref_t = " + self.mdp.pop('ref_t', '300 300')) # Pressure coupling if md: mdp_list.append("\n;Pressure coupling") if nvt: mdp_list.append("pcoupl = " + self.mdp.pop('pcoupl', 'no')) if npt or free: mdp_list.append("pcoupl = " + self.mdp.pop('pcoupl', 'Parrinello-Rahman')) mdp_list.append("pcoupltype = " + self.mdp.pop('pcoupltype', 'isotropic')) mdp_list.append("tau_p = " + self.mdp.pop('tau_p', '1.0')) mdp_list.append("ref_p = " + self.mdp.pop('ref_p', '1.0')) mdp_list.append("compressibility = " + self.mdp.pop('compressibility', '4.5e-5')) mdp_list.append("refcoord_scaling = " + self.mdp.pop('refcoord_scaling', 'com')) # Dispersion correction if md: mdp_list.append("\n;Dispersion correction") mdp_list.append("DispCorr = " + self.mdp.pop('DispCorr', 'EnerPres')) # Velocity generation if md: mdp_list.append("\n;Velocity generation") if nvt: mdp_list.append("gen_vel = " + self.mdp.pop('gen_vel', 'yes')) mdp_list.append("gen_temp = " + self.mdp.pop('gen_temp', '300')) mdp_list.append("gen_seed = " + self.mdp.pop('gen_seed', '-1')) if npt or free: mdp_list.append("gen_vel = " + self.mdp.pop('gen_vel', 'no')) #Periodic boundary conditions mdp_list.append("\n;Periodic boundary conditions") mdp_list.append("pbc = " + self.mdp.pop('pbc', 'xyz')) if index: mdp_list =[";This mdp file has been created by the pymdsetup.gromacs_wrapper.grompp.create_mdp()"] mdp_list.insert(0, ";This mdp file has been created by the pymdsetup.gromacs_wrapper.grompp.create_mdp()") # Adding the rest of parameters in the config file to the MDP file for k, v in self.mdp.iteritems(): if k != 'type': mdp_list.append(str(k) + ' = '+str(v)) with open(mdp_file_path, 'w') as mdp: for line in mdp_list: mdp.write(line + '\n') return mdp_file_path