def wrapper(*args, **kwargs):
            """ Wraps a python function so that it will be executed remotely using a compute engine

            Note:
                At runtime, this documentation should be replaced with that of the wrapped function
            """
            # If the wrapper is not enabled, just run the wrapped function as normal.
            f = func  # keeps a reference to the original function in this closure
            if not wrapper.enabled:
                return f(*args, **kwargs)

            wait = kwargs.get('wait', True)

            # Bind instance methods to their objects
            if self.is_imethod:
                f, args = _bind_instance_method(f, args)

            # Submit job to remote engine
            python_call = bpy.PythonCall(f, *args, **kwargs)
            image = utils.if_not_none(self.image, configuration.config.default_python_image)
            engine = utils.if_not_none(self.engine, mdt.compute.get_engine())
            job = bpy.PythonJob(engine,
                                image,
                                python_call,
                                name=self.jobname,
                                sendsource=self.sendsource)

            if self.display:
                uibase.display_log(job.get_display_object(), title=f.__name__)

            if wait:
                job.wait()
                return job.result
            else:
                return job
Beispiel #2
0
def am1_bcc_charges(mol, minsteps=None, wait=True):
    """ Doesn't work yet ..."""
    charge = utils.if_not_none(mol.charge, 0)

    engine = mdt.compute.get_engine()
    image = compute.get_image_path(IMAGE, engine)
    command = 'antechamber -fi pdb -i mol.pdb -fo mol2 -o out.mol2 -c bcc -an n'
    if charge != 0: command += ' -nc %d' % charge
    if minsteps is not None: command += ' -ek "maxcyc=%d"' % minsteps

    def parse_mol2(job):
        """Callback to complete the job"""
        atom_info = utils.DotDict(job=job)
        lines = iter(job.get_output('out.mol2').read().split('\n'))
        while True:
            line = lines.next()
            fields = line.split()
            if fields[0] == 'ATOM':
                idx = int(fields[1]) - 1
                name = fields[2]
                assert mol.atoms[idx].name == name
                atom_info[mol.atoms[idx]] = utils.DotDict(partialcharge=u.q_e *
                                                          float(fields[-2]),
                                                          atomtype=fields[-1])
        return atom_info

    job = engine.launch(image,
                        command=command,
                        name="am1-bcc, %s" % mol.name,
                        inputs={'mol.pdb': mol.write(format='pdb')},
                        when_finished=parse_mol2)
    uibase.display_log(job.get_display_object(), job.name)
    if not wait: return job()
    else: job.wait()
Beispiel #3
0
def show_parameterization_results(errormessages, molin, molout=None):
    if uibase.widgets_enabled:
        report = ParameterizationDisplay(errormessages, molin, molout)
        uibase.display_log(report, title='ERRORS/WARNINGS', show=True)

    else:
        print 'Forcefield assignment: %s' % ('Success' if molout is not None else 'Failure')
        for err in errormessages:
            print utils.html_to_text(err.desc)
def show_parameterization_results(errormessages, molin, molout=None):
    if uibase.widgets_enabled:
        report = ParameterizationDisplay(errormessages, molin, molout)
        uibase.display_log(report, title='ERRORS/WARNINGS', show=True)

    else:
        print 'Forcefield assignment: %s' % ('Success' if molout is not None else 'Failure')
        for err in errormessages:
            print utils.html_to_text(err.desc)
Beispiel #5
0
def assign_forcefield(mol, **kwargs):
    """ see run_tleap docstring """
    from moldesign.widgets.parameterization import ParameterizationDisplay
    job = run_tleap(mol, **kwargs)

    if 'output.inpcrd' in job.get_output():
        prmtop = job.get_output('output.prmtop')
        inpcrd = job.get_output('output.inpcrd')
        params = AmberParameters(prmtop, inpcrd, job)
        newmol = mdt.read_amber(params.prmtop, params.inpcrd)
        newmol.ff.amber_params = params
    else:
        newmol = None

    report = ParameterizationDisplay(job, mol, molout=newmol)
    uibase.display_log(report, title='ERRORS/WARNINGS', show=True)

    if newmol is not None:
        return newmol
    else:
        raise ParameterizationError(
            'TLeap failed to assign force field parameters for %s' % mol, job)
Beispiel #6
0
def get_gaff_parameters(mol, charges, image=IMAGE, engine=None):
    """ Doesn't work yet"""
    inputs = {}

    # Add charges to molecule
    inputs['mol.charges'] = '\n'.join(map(str, charges))
    inputs['mol.mol2'] = mol.write(format='mol2')

    # Creates a mol2 file with the passed charges
    cmds.append(
        'antechamber -i mol.mol2 -fi mol2 -o mol_charged.mol2 -fo mol2 -c rc -cf mol.charges'
    )

    # Add missing parameters, write out library and parameter files
    cmds.append('parmchk -i mol_charged.mol2 -f mol2 -o mol.frcmod')

    # Create the lib file
    cmds.append('tleap -f lea.in')
    inputs['leap.in'] = '\n'.join([
        "source leaprc.%s" % ff, "source leaprc.gaff",
        "LIG = loadmol2 mol_charged.mol2", "fmod = loadamberparams mol.frcmod",
        "check LIG", "saveoff LIG mol.lib",
        "saveamberparm LIG mol.prmtop mol.inpcrd", "quit\n"
    ])

    # Submit the job and wait
    job = engine.launch(imagename,
                        ' && '.join(cmds),
                        inputs=inputs,
                        name="GAFF assignments" % mol.name)
    uibase.display_log(job.get_display_object(), "tleap, %s" % mol.name)
    job.wait()

    param = GAFFParameters(job.get_output('mol.lib'),
                           job.get_output('mol.frcmod'), job)
    return param