def _system_from_amber(self, *receptor_file, **kwargs): """ Creates an OpenMM system from the prmtop/inpcrd Amber files Parameters ---------- receptor_file : list of str List of filenames corresponding to the prmtop and inpcrd Amber files of the receptor. Returns ------- system : openmm.System prmtop.topology: openmm.Topology inpcrd.positions: list List of atomic positions. total_charge: int Total charge of the system. """ input = {} for file in receptor_file: name, ext = utils.parse_ligand_filename(file) input[ext] = file prmtop = app.amberprmtopfile.AmberPrmtopFile(input['.prmtop']) inpcrd = app.amberinpcrdfile.AmberInpcrdFile(input['.inpcrd']) prm = pmd.amber.AmberParm(input['.prmtop']) charge = int(floor(0.5 + pmd.tools.netCharge(prm).execute())) system = prmtop.createSystem(**kwargs) return self._fix_particle_sigmas( system), prmtop.topology, inpcrd.positions, charge
def run_antechamber(molecule_name, input_filename, charge_method="bcc", net_charge=None, gaff_mol2_filename=None, frcmod_filename=None, input_format='mol2', resname=False, log_debug_output=False): """Run AmberTools antechamber and parmchk2 to create GAFF mol2 and frcmod files. Parameters ---------- molecule_name : str Name of the molecule to be parameterized, will be used in output filenames. ligand_filename : str The molecule to be parameterized. Must be tripos mol2 format. charge_method : str, optional If not None, the charge method string will be passed to Antechamber. net_charge : int, optional If not None, net charge of the molecule to be parameterized. If None, Antechamber sums up partial charges from the input file. gaff_mol2_filename : str, optional, default=None Name of GAFF mol2 filename to output. If None, uses local directory and molecule_name frcmod_filename : str, optional, default=None Name of GAFF frcmod filename to output. If None, uses local directory and molecule_name input_format : str, optional, default='mol2' Format specifier for input file to pass to antechamber. resname : bool, optional, default=False Set the residue name used within output files to molecule_name log_debug_output : bool, optional, default=False If true, will send output of tleap to logger. Returns ------- gaff_mol2_filename : str GAFF format mol2 filename produced by antechamber frcmod_filename : str Amber frcmod file produced by prmchk """ utils = import_("openmoltools.utils") ext = utils.parse_ligand_filename(input_filename)[1] if gaff_mol2_filename is None: gaff_mol2_filename = molecule_name + '.gaff.mol2' if frcmod_filename is None: frcmod_filename = molecule_name + '.frcmod' #Build absolute paths for input and output files gaff_mol2_filename = os.path.abspath( gaff_mol2_filename ) frcmod_filename = os.path.abspath( frcmod_filename ) input_filename = os.path.abspath( input_filename ) def read_file_contents(filename): infile = open(filename, 'r') contents = infile.read() infile.close() return contents #Use temporary directory context to do this to avoid issues with spaces in filenames, etc. with mdtraj.utils.enter_temp_directory(): local_input_filename = 'in.' + input_format shutil.copy( input_filename, local_input_filename ) # Run antechamber. cmd = "antechamber -i %(local_input_filename)s -fi %(input_format)s -o out.mol2 -fo mol2 -s 2" % vars() if charge_method is not None: cmd += ' -c %s' % charge_method if net_charge is not None: cmd += ' -nc %d' % net_charge if resname: cmd += ' -rn %s' % molecule_name if log_debug_output: logger.debug(cmd) output = getoutput(cmd) if not os.path.exists('out.mol2'): msg = "antechamber failed to produce output mol2 file\n" msg += "command: %s\n" % cmd msg += "output:\n" msg += 8 * "----------" + '\n' msg += output msg += 8 * "----------" + '\n' msg += "input mol2:\n" msg += 8 * "----------" + '\n' msg += read_file_contents(local_input_filename) msg += 8 * "----------" + '\n' raise Exception(msg) if log_debug_output: logger.debug(output) # Run parmchk. cmd = "parmchk2 -i out.mol2 -f mol2 -o out.frcmod" if log_debug_output: logger.debug(cmd) output = getoutput(cmd) if not os.path.exists('out.frcmod'): msg = "parmchk2 failed to produce output frcmod file\n" msg += "command: %s\n" % cmd msg += "output:\n" msg += 8 * "----------" + '\n' msg += output msg += 8 * "----------" + '\n' msg += "input mol2:\n" msg += 8 * "----------" + '\n' msg += read_file_contents('out.mol2') msg += 8 * "----------" + '\n' raise Exception(msg) if log_debug_output: logger.debug(output) check_for_errors(output) #Copy back shutil.copy( 'out.mol2', gaff_mol2_filename ) shutil.copy( 'out.frcmod', frcmod_filename ) return gaff_mol2_filename, frcmod_filename
def run_antechamber(molecule_name, input_filename, charge_method="bcc", net_charge=None, gaff_mol2_filename=None, frcmod_filename=None): """Run AmberTools antechamber and parmchk2 to create GAFF mol2 and frcmod files. Parameters ---------- molecule_name : str Name of the molecule to be parameterized, will be used in output filenames. ligand_filename : str The molecule to be parameterized. Must be tripos mol2 format. charge_method : str, optional If not None, the charge method string will be passed to Antechamber. net_charge : int, optional If not None, net charge of the molecule to be parameterized. If None, Antechamber sums up partial charges from the input file. gaff_mol2_filename : str, optional, default=None Name of GAFF mol2 filename to output. If None, uses local directory and molecule_name frcmod_filename : str, optional, default=None Name of GAFF frcmod filename to output. If None, uses local directory and molecule_name Returns ------- gaff_mol2_filename : str GAFF format mol2 filename produced by antechamber frcmod_filename : str Amber frcmod file produced by prmchk """ utils = import_("openmoltools.utils") ext = utils.parse_ligand_filename(input_filename)[1] filetype = ext[1:] if filetype != "mol2": raise(ValueError("Must input mol2 filename")) if gaff_mol2_filename is None: gaff_mol2_filename = molecule_name + '.gaff.mol2' if frcmod_filename is None: frcmod_filename = molecule_name + '.frcmod' #Build absolute paths for input and output files gaff_mol2_filename = os.path.abspath( gaff_mol2_filename ) frcmod_filename = os.path.abspath( frcmod_filename ) input_filename = os.path.abspath( input_filename ) #Use temporary directory context to do this to avoid issues with spaces in filenames, etc. with mdtraj.utils.enter_temp_directory(): shutil.copy( input_filename, 'in.mol2' ) cmd = "antechamber -i in.mol2 -fi mol2 -o out.mol2 -fo mol2 -s 2" if charge_method is not None: cmd += ' -c %s' % charge_method if net_charge is not None: cmd += ' -nc %d' % net_charge logger.debug(cmd) output = getoutput(cmd) logger.debug(output) cmd = "parmchk2 -i out.mol2 -f mol2 -o out.frcmod" logger.debug(cmd) output = getoutput(cmd) logger.debug(output) check_for_errors( output ) #Copy back shutil.copy( 'out.mol2', gaff_mol2_filename ) shutil.copy( 'out.frcmod', frcmod_filename ) return gaff_mol2_filename, frcmod_filename
def run_antechamber(molecule_name, input_filename, charge_method="bcc", net_charge=None, gaff_mol2_filename=None, frcmod_filename=None): """Run AmberTools antechamber and parmchk2 to create GAFF mol2 and frcmod files. Parameters ---------- molecule_name : str Name of the molecule to be parameterized, will be used in output filenames. ligand_filename : str The molecule to be parameterized. Must be tripos mol2 format. charge_method : str, optional If not None, the charge method string will be passed to Antechamber. net_charge : int, optional If not None, net charge of the molecule to be parameterized. If None, Antechamber sums up partial charges from the input file. gaff_mol2_filename : str, optional, default=None Name of GAFF mol2 filename to output. If None, uses local directory and molecule_name frcmod_filename : str, optional, default=None Name of GAFF frcmod filename to output. If None, uses local directory and molecule_name Returns ------- gaff_mol2_filename : str GAFF format mol2 filename produced by antechamber frcmod_filename : str Amber frcmod file produced by prmchk """ utils = import_("openmoltools.utils") ext = utils.parse_ligand_filename(input_filename)[1] filetype = ext[1:] if filetype != "mol2": raise (ValueError("Must input mol2 filename")) if gaff_mol2_filename is None: gaff_mol2_filename = molecule_name + '.gaff.mol2' if frcmod_filename is None: frcmod_filename = molecule_name + '.frcmod' #Build absolute paths for input and output files gaff_mol2_filename = os.path.abspath(gaff_mol2_filename) frcmod_filename = os.path.abspath(frcmod_filename) input_filename = os.path.abspath(input_filename) #Use temporary directory context to do this to avoid issues with spaces in filenames, etc. with mdtraj.utils.enter_temp_directory(): shutil.copy(input_filename, 'in.mol2') cmd = "antechamber -i in.mol2 -fi mol2 -o out.mol2 -fo mol2 -s 2" if charge_method is not None: cmd += ' -c %s' % charge_method if net_charge is not None: cmd += ' -nc %d' % net_charge logger.debug(cmd) output = getoutput(cmd) logger.debug(output) cmd = "parmchk2 -i out.mol2 -f mol2 -o out.frcmod" logger.debug(cmd) output = getoutput(cmd) logger.debug(output) check_for_errors(output) #Copy back shutil.copy('out.mol2', gaff_mol2_filename) shutil.copy('out.frcmod', frcmod_filename) return gaff_mol2_filename, frcmod_filename