Esempio n. 1
0
    def _create_models(self, env, base_models, model_id, query_id):

        a = automodel(env,
                      alnfile=self._aln_file(model_id, query_id),
                      knowns=base_models,
                      sequence=str(query_id),
                      assess_methods=self._assess_methods)
        a.starting_model = 1
        a.ending_model = self.model_count
        a.md_level = self._refinement

        # TODO assessing with {assess_methods}
        _log.debug(
            "Generating {model_count} model/s for {orf} with {base_models} ".
            format(orf=query_id,
                   base_models=base_models,
                   model_count=self.model_count))

        if self.parallel_jobs > 1:
            j = job()
            for _ in range(0, self.parallel_jobs):
                j.append(local_slave())
            a.use_parallel_job(j)

        model = a.make()
        if "OverflowError" in str(a.outputs[0]["failure"].__class__):
            raise ModellerOverflowError(a.outputs[0]["failure"], base_models)
        _log.debug(
            "{model_count} models for {orf} with {base_models} where generated "
            .format(orf=query_id,
                    base_models=base_models,
                    model_count=self.model_count))
Esempio n. 2
0
    def _create_models(self, env, base_models, model_id, query_id):
        class MyModel(automodel):
            def special_patches(self, aln):
                # Rename both chains and renumber the residues in each
                start = int(aln[1].range[0].split(":")[0])
                self.rename_segments(segment_ids=['A'],
                                     renumber_residues=start)
                # self.chains[0].name = 'A'

        a = MyModel(env,
                    alnfile=self._aln_file(model_id, query_id),
                    knowns=base_models,
                    sequence=str(query_id),
                    assess_methods=self._assess_methods)
        a.starting_model = 1
        a.ending_model = self.model_count
        a.md_level = self._refinement

        # TODO assessing with {assess_methods}
        _log.debug(
            "Generating {model_count} model/s for {orf} with {base_models} ".
            format(orf=query_id,
                   base_models=base_models,
                   model_count=self.model_count))

        if self.parallel_jobs > 1:
            j = job()
            for _ in range(0, self.parallel_jobs):
                j.append(local_slave())
            a.use_parallel_job(j)

        model = a.make()

        if "OverflowError" in str(a.outputs[0]["failure"].__class__):
            raise ModellerOverflowError(a.outputs[0]["failure"], base_models)
        _log.debug(
            "{model_count} models for {orf} with {base_models} where generated "
            .format(orf=query_id,
                    base_models=base_models,
                    model_count=self.model_count))
Esempio n. 3
0
def peptide_rebuild_modeller(name, selection='all', hetatm=0, sequence=None,
        nmodels=1, hydro=0, quiet=1, *, _self=cmd):
    '''
DESCRIPTION

    Remodel the given selection using modeller. This is useful for example to
    build incomplete sidechains. More complicated modelling tasks are not
    the intention of this simple interface.

    Side effects: Alters "type" property for MSE residues in selection
    (workaround for bug #3512313).

USAGE

    peptide_rebuild_modeller name [, selection [, hetatm [, sequence ]]]

ARGUMENTS

    name = string: new object name

    selection = string: atom selection

    hetatm = 0/1: read and model HETATMs (ligands) {default: 0}

    sequence = string: if provided, use this sequence instead of the
    template sequence {default: None}

    nmodels = int: number of models (states) to generate {default: 1}
    '''
    import modeller
    from modeller.automodel import automodel, allhmodel

    import tempfile, shutil, os
    _assert_package_import()
    from .editing import update_identifiers

    nmodels, hetatm, quiet = int(nmodels), int(hetatm), int(quiet)

    if int(hydro):
        automodel = allhmodel

    tempdir = tempfile.mkdtemp()
    pdbfile = os.path.join(tempdir, 'template.pdb')
    alnfile = os.path.join(tempdir, 'aln.pir')

    cwd = os.getcwd()
    os.chdir(tempdir)

    if not quiet:
        print(' Notice: PWD=%s' % (tempdir))

    try:
        modeller.log.none()
        env = modeller.environ()
        env.io.hetatm = hetatm

        # prevent PyMOL to put TER records before MSE residues (bug #3512313)
        _self.alter('(%s) and polymer' % (selection), 'type="ATOM"')

        _self.save(pdbfile, selection)
        mdl = modeller.model(env, file=pdbfile)

        aln = modeller.alignment(env)
        aln.append_model(mdl, align_codes='foo', atom_files=pdbfile)

        # get sequence from non-present atoms
        if not sequence and _self.count_atoms('(%s) & !present' % (selection)):
            sequence = get_seq(selection)

        if sequence:
            aln.append_sequence(sequence)
            aln[-1].code = 'bar'
            aln.malign()
        aln.write(alnfile)

        a = automodel(env, alnfile=alnfile, sequence=aln[-1].code,
                knowns=[s.code for s in aln if s.prottyp.startswith('structure')])
        a.max_ca_ca_distance = 30.0

        if nmodels > 1:
            a.ending_model = nmodels
            from multiprocessing import cpu_count
            ncpu = min(cpu_count(), nmodels)
            if ncpu > 1:
                from modeller import parallel
                job = parallel.job(parallel.local_slave()
                        for _ in range(ncpu))
                a.use_parallel_job(job)

        a.make()

        for output in a.outputs:
            _self.load(output['name'], name, quiet=quiet)
    finally:
        os.chdir(cwd)
        shutil.rmtree(tempdir)

    _self.align(name, selection, cycles=0)
    if not sequence:
        update_identifiers(name, selection, _self=_self)

    if not quiet:
        print(' peptide_rebuild_modeller: done')
Esempio n. 4
0
def peptide_rebuild_modeller(name, selection='all', hetatm=0, sequence=None,
        nmodels=1, hydro=0, quiet=1):
    '''
DESCRIPTION

    Remodel the given selection using modeller. This is useful for example to
    build incomplete sidechains. More complicated modelling tasks are not
    the intention of this simple interface.

    Side effects: Alters "type" property for MSE residues in selection
    (workaround for bug #3512313).

USAGE

    peptide_rebuild_modeller name [, selection [, hetatm [, sequence ]]]

ARGUMENTS

    name = string: new object name

    selection = string: atom selection

    hetatm = 0/1: read and model HETATMs (ligands) {default: 0}

    sequence = string: if provided, use this sequence instead of the
    template sequence {default: None}

    nmodels = int: number of models (states) to generate {default: 1}
    '''
    try:
        import modeller
        from modeller.automodel import automodel, allhmodel
    except ImportError:
        print(' Error: failed to import "modeller"')
        raise CmdException

    import tempfile, shutil, os
    from .editing import update_identifiers

    nmodels, hetatm, quiet = int(nmodels), int(hetatm), int(quiet)

    if int(hydro):
        automodel = allhmodel

    tempdir = tempfile.mkdtemp()
    pdbfile = os.path.join(tempdir, 'template.pdb')
    alnfile = os.path.join(tempdir, 'aln.pir')

    cwd = os.getcwd()
    os.chdir(tempdir)

    if not quiet:
        print(' Notice: PWD=%s' % (tempdir))

    try:
        modeller.log.none()
        env = modeller.environ()
        env.io.hetatm = hetatm

        # prevent PyMOL to put TER records before MSE residues (bug #3512313)
        cmd.alter('(%s) and polymer' % (selection), 'type="ATOM"')

        cmd.save(pdbfile, selection)
        mdl = modeller.model(env, file=pdbfile)

        aln = modeller.alignment(env)
        aln.append_model(mdl, align_codes='foo', atom_files=pdbfile)
        if sequence:
            aln.append_sequence(sequence)
            aln[-1].code = 'bar'
            aln.malign()
        aln.write(alnfile)

        a = automodel(env, alnfile=alnfile, sequence=aln[-1].code,
                knowns=[s.code for s in aln if s.prottyp.startswith('structure')])
        a.max_ca_ca_distance = 30.0

        if nmodels > 1:
            a.ending_model = nmodels
            from multiprocessing import cpu_count
            ncpu = min(cpu_count(), nmodels)
            if ncpu > 1:
                from modeller import parallel
                job = parallel.job(parallel.local_slave()
                        for _ in range(ncpu))
                a.use_parallel_job(job)

        a.make()

        for output in a.outputs:
            cmd.load(output['name'], name, quiet=quiet)
    finally:
        os.chdir(cwd)
        shutil.rmtree(tempdir)

    cmd.align(name, selection, cycles=0)
    if not sequence:
        update_identifiers(name, selection)

    if not quiet:
        print(' peptide_rebuild_modeller: done')