def _antechamber_calc_charges(mol, ambname, chargename, kwargs): charge = utils.if_not_none(mol.charge, 0) command = 'antechamber -fi mol2 -i mol.mol2 -fo mol2 -o out.mol2 -c %s -an n'%ambname if charge != 0: command += ' -nc %d' % charge.value_in(u.q_e) def finish_job(job): """Callback to complete the job""" lines = iter(job.get_output('out.mol2').read().split('\n')) charges = utils.DotDict(type='atomic') line = lines.next() while line.strip()[:len('@<TRIPOS>ATOM')] != '@<TRIPOS>ATOM': line = lines.next() line = lines.next() while line.strip()[:len('@<TRIPOS>BOND')] != '@<TRIPOS>BOND': fields = line.split() idx = int(fields[0])-1 assert mol.atoms[idx].name == fields[1] charges[mol.atoms[idx]] = u.q_e*float(fields[-1]) line = lines.next() mol.properties[chargename] = charges return charges job = pyccc.Job(image=mdt.compute.get_image_path(IMAGE), command=command, name="%s, %s" % (chargename, mol.name), inputs={'mol.mol2': mol.write(format='mol2')}, when_finished=finish_job) return compute.run_job(job, _return_result=True, **kwargs)
def _antechamber_calc_charges(mol, ambname, chargename, kwargs): charge = utils.if_not_none(mol.charge, 0) command = 'antechamber -fi mol2 -i mol.mol2 -fo mol2 -o out.mol2 -c %s -an n' % ambname if charge != 0: command += ' -nc %d' % charge.value_in(u.q_e) def finish_job(job): """Callback to complete the job""" lines = iter(job.get_output('out.mol2').read().split('\n')) charges = utils.DotDict(type='atomic') line = lines.next() while line.strip()[:len('@<TRIPOS>ATOM')] != '@<TRIPOS>ATOM': line = lines.next() line = lines.next() while line.strip()[:len('@<TRIPOS>BOND')] != '@<TRIPOS>BOND': fields = line.split() idx = int(fields[0]) - 1 assert mol.atoms[idx].name == fields[1] charges[mol.atoms[idx]] = u.q_e * float(fields[-1]) line = lines.next() mol.properties[chargename] = charges return charges job = pyccc.Job(image=mdt.compute.get_image_path(IMAGE), command=command, name="%s, %s" % (chargename, mol.name), inputs={'mol.mol2': mol.write(format='mol2')}, when_finished=finish_job) return compute.run_job(job, _return_result=True, **kwargs)
def run_tleap(mol, forcefields=None, parameters=None, **kwargs): """ Drives tleap to create a prmtop and inpcrd file. Specifically uses the AmberTools 16 tleap distribution. Defaults are as recommended in the ambertools manual. Args: mol (moldesign.Molecule): Molecule to set up forcefields (List[str]): list of the names of forcefields to use (see AmberTools manual for descriptions) parameters (List[ExtraAmberParameters]): (optional) list of amber parameters for non-standard residues **kwargs: keyword arguments to :meth:`compute.run_job` References: Ambertools Manual, http://ambermd.org/doc12/Amber16.pdf. See page 33 for forcefield recommendations. """ # Prepare input for tleap if forcefields is None: forcefields = mdt.forcefields.ffdefaults.values() leapstr = ['source %s' % LEAPRCFILES[ff] for ff in forcefields] inputs = {'input.pdb': mol.write(format='pdb')} if parameters: if hasattr(parameters, 'lib') or hasattr(parameters, 'frcmod'): parameters = [parameters] for ipmtr, p in enumerate(parameters): frcname = 'res%d.frcmod' % ipmtr libname = 'res%d.lib' % ipmtr inputs[frcname] = p.frcmod inputs[libname] = p.lib leapstr.append('loadAmberParams %s' % frcname) leapstr.append('loadoff %s' % libname) leapstr.append('mol = loadpdb input.pdb\n' "check mol\n" "saveamberparm mol output.prmtop output.inpcrd\n" "savepdb mol output.pdb\n" "quit\n") inputs['input.leap'] = '\n'.join(leapstr) job = pyccc.Job(image=compute.get_image_path(IMAGE), command='tleap -f input.leap', inputs=inputs, name="tleap, %s" % mol.name) return compute.run_job(job, **kwargs)
def run_tleap(mol, protein='ff14SB', dna='OL15', rna='OL3', carbohydrate='GLYCAM_06j-1', lipid='lipid14', water='tip3p', organic='gaff2', off_files=(), frcmod_files=(), **kwargs): """ Drives tleap to create a prmtop and inpcrd file. Specifically uses the AmberTools 16 tleap distribution. Defaults are as recommended in the ambertools manual. Args: mol (moldesign.Molecule): Molecule to set up protein (str): protein forcefield name (default:ff14SB) dna (str): dna forcefield name (default: OL15) rna (str): rna forcefield name (default: OL3) carbohydrate (str): carbohydrate forcefield name (default: GLYCAM_06j) lipid (str): lipid forcefield name (default: lipid14) water (str): water forcefield name (default: tip3p) organic (str): organic forcefield name (default: gaff2) off_files (List[batch.FileContainer]): frcmod_files (List[batch.FileContainer]): **kwargs: keyword arguments to :meth:`compute.run_job` References: Ambertools Manual, http://ambermd.org/doc12/Amber16.pdf. See page 33 for forcefield recommendations. """ # Prepare input for tleap leapstr = [ 'source %s' % LEAPRCFILES[ff] for ff in (protein, dna, rna, carbohydrate, lipid, water, organic) ] for frcmod in frcmod_files: fname = frcmod.dumphere() leapstr.append('loadamberparam %s' % fname) for off in off_files: fname = off.dumphere() leapstr.append('loadoff %s' % fname) leapstr.append('mol = loadpdb input.pdb\n' "check mol\n" "saveamberparm mol output.prmtop output.inpcrd\n" "quit\n") # Launch the job inputs = { 'input.pdb': mol.write(format='pdb'), 'input.leap': '\n'.join(leapstr) } job = pyccc.Job(image=compute.get_image_path(IMAGE), command='tleap -f input.leap', inputs=inputs, name="tleap, %s" % mol.name) return compute.run_job(job, **kwargs)