Ejemplo n.º 1
0
    def fragment(name, object=None, origin=1, zoom=0, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "fragment" retrieves a 3D structure from the fragment library,
    which is currently pretty meager (just amino acids).

USAGE

    fragment name

    '''
        r = DEFAULT_ERROR
        try:
            if object == None:
                object = name
            model = fragments.get(str(name))
            la = len(model.atom)
            if la and int(origin):
                position = _self.get_position()
                for c in range(0, 3):
                    mean_c = sum([a.coord[c] for a in model.atom]) / la
                    mean_c = position[c] - mean_c
                    for a in model.atom:
                        a.coord[c] += mean_c
            r = _self.load_model(model,
                                 str(object),
                                 quiet=quiet,
                                 zoom=zoom,
                                 _self=_self)
        except IOError:
            raise pymol.CmdException("unable to load fragment '%s'." % name)
        if _self._raising(r, _self): raise pymol.CmdException
        return r
Ejemplo n.º 2
0
    def fragment(name, object=None, origin=1, zoom=0, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "fragment" retrieves a 3D structure from the fragment library,
    which is currently pretty meager (just amino acids).

USAGE

    fragment name

    '''
        r = DEFAULT_ERROR
        try:
            if object==None:
                object=name
            model = fragments.get(str(name))
            la = len(model.atom)
            if la and int(origin):
                position = _self.get_position()
                for c in range(0,3):
                    mean_c = sum([a.coord[c] for a in model.atom]) / la
                    mean_c = position[c] - mean_c
                    for a in model.atom:
                        a.coord[c] += mean_c
            r = _self.load_model(model,str(object),quiet=quiet,zoom=zoom, _self=_self)
        except IOError:
            raise pymol.CmdException("unable to load fragment '%s'." % name)
        if _self._raising(r,_self): raise pymol.CmdException                                    
        return r
Ejemplo n.º 3
0
    def fragment(name, object=None, origin=1, zoom=0, quiet=1, _self=cmd):
        '''
DESCRIPTION

    "fragment" retrieves a 3D structure from the fragment library,
    which is currently pretty meager (just amino acids).

USAGE

    fragment name

    '''
        r = DEFAULT_ERROR
        try:
            save = _self.get_setting_legacy('auto_zoom')
            if object == None:
                object = name
            model = fragments.get(str(name))
            la = len(model.atom)
            if la:
                mean = map(lambda x, la=la: x / la, [
                    reduce(operator.__add__,
                           map(lambda a: a.coord[0], model.atom)),
                    reduce(operator.__add__,
                           map(lambda a: a.coord[1], model.atom)),
                    reduce(operator.__add__,
                           map(lambda a: a.coord[2], model.atom))
                ])
                position = _self.get_position()
                for c in range(0, 3):
                    mean[c] = position[c] - mean[c]
                    map(lambda a, x=mean[c], c=c: _self._adjust_coord(a, c, x),
                        model.atom)
                mean = map(lambda x, la=la: x / la, [
                    reduce(operator.__add__,
                           map(lambda a: a.coord[0], model.atom)),
                    reduce(operator.__add__,
                           map(lambda a: a.coord[1], model.atom)),
                    reduce(operator.__add__,
                           map(lambda a: a.coord[2], model.atom))
                ])
            r = _self.load_model(model, str(object), quiet=quiet, zoom=zoom)
        except IOError:
            print "Error: unable to load fragment '%s'." % name
        except:
            traceback.print_exc()
            print "Error: unable to load fragment '%s'." % name
        if _self._raising(r, _self): raise pymol.CmdException
        return r
Ejemplo n.º 4
0
    def fragment(name, object=None, origin=1, zoom=0, quiet=1, _self=cmd):
        """
DESCRIPTION

    "fragment" retrieves a 3D structure from the fragment library,
    which is currently pretty meager (just amino acids).

USAGE

    fragment name

    """
        r = DEFAULT_ERROR
        try:
            save = _self.get_setting_legacy("auto_zoom")
            if object == None:
                object = name
            model = fragments.get(str(name))
            la = len(model.atom)
            if la:
                mean = map(
                    lambda x, la=la: x / la,
                    [
                        reduce(operator.__add__, map(lambda a: a.coord[0], model.atom)),
                        reduce(operator.__add__, map(lambda a: a.coord[1], model.atom)),
                        reduce(operator.__add__, map(lambda a: a.coord[2], model.atom)),
                    ],
                )
                position = _self.get_position()
                for c in range(0, 3):
                    mean[c] = position[c] - mean[c]
                    map(lambda a, x=mean[c], c=c: _self._adjust_coord(a, c, x), model.atom)
                mean = map(
                    lambda x, la=la: x / la,
                    [
                        reduce(operator.__add__, map(lambda a: a.coord[0], model.atom)),
                        reduce(operator.__add__, map(lambda a: a.coord[1], model.atom)),
                        reduce(operator.__add__, map(lambda a: a.coord[2], model.atom)),
                    ],
                )
            r = _self.load_model(model, str(object), quiet=quiet, zoom=zoom)
        except IOError:
            print "Error: unable to load fragment '%s'." % name
        except:
            traceback.print_exc()
            print "Error: unable to load fragment '%s'." % name
        if _self._raising(r, _self):
            raise pymol.CmdException
        return r
Ejemplo n.º 5
0
def peptide_rebuild(name, selection='all', cycles=1000, state=1, quiet=1, *, _self=cmd):
    '''
DESCRIPTION

    Rebuild the peptide from selection. All atoms which are present in
    selection will be kept fixed, while atoms missing in selection are
    placed by sculpting.

USAGE

    peptide_rebuild name [, selection [, cycles [, state ]]]

SEE ALSO

    stub2ala, add_missing_atoms, peptide_rebuild_modeller
    '''
    from chempy import fragments, feedback, models

    cycles, state, quiet = int(cycles), int(state), int(quiet)

    # suppress feedback for model merging
    feedback['actions'] = False

    # work with named selection
    namedsele = _self.get_unused_name('_')
    _self.select(namedsele, '{} & present'.format(selection), 0)

    identifiers = []
    _self.iterate(namedsele + ' and polymer and guide and alt +A',
            'identifiers.append([segi,chain,resi,resv,resn])', space=locals())

    model = models.Indexed()
    for (segi,chain,resi,resv,resn) in identifiers:
        try:
            fname = resn.lower() if resn != 'MSE' else 'met'
            frag = fragments.get(fname)
        except IOError:
            print(' Warning: unknown residue: ' + resn)
            continue

        for a in frag.atom:
            a.segi = segi
            a.chain = chain
            a.resi = resi
            a.resi_number = resv
            a.resn = resn

        model.merge(frag)

    if not quiet:
        print(' Loading model...')

    _self.load_model(model, name, 1, zoom=0)
    if _self.get_setting_boolean('auto_remove_hydrogens'):
        _self.remove(name + ' and hydro')

    _self.protect(name + ' in ' + namedsele)
    _self.sculpt_activate(name)
    _self.update(name, namedsele, 1, state)
    _self.delete(namedsele)

    if not quiet:
        print(' Sculpting...')

    _self.set('sculpt_field_mask', 0x003, name) # bonds and angles only
    _self.sculpt_iterate(name, 1, int(cycles / 4))

    _self.set('sculpt_field_mask', 0x09F, name) # local + torsions
    _self.sculpt_iterate(name, 1, int(cycles / 4))

    _self.set('sculpt_field_mask', 0x0FF, name) # ... + vdw
    _self.sculpt_iterate(name, 1, int(cycles / 2))

    _self.sculpt_deactivate(name)
    _self.deprotect(name)
    _self.unset('sculpt_field_mask', name)

    if not quiet:
        print(' Connecting peptide...')

    pairs = _self.find_pairs(name + ' and name C', name + ' and name N', 1, 1, 2.0)
    for pair in pairs:
        _self.bond(*pair)
    _self.h_fix(name)

    if not quiet:
        print(' peptide_rebuild: done')
Ejemplo n.º 6
0
def add_missing_atoms(selection='all', cycles=200, quiet=1, *, _self=cmd):
    '''
DESCRIPTION

    Mutate those residues to themselves which have missing atoms

SEE ALSO

    stub2ala
    '''
    from collections import defaultdict
    from chempy import fragments

    cycles, quiet = int(cycles), int(quiet)

    reference = {
        'ALA': set(['CB']),
        'ARG': set(['CB', 'CG', 'NE', 'CZ', 'NH1', 'NH2', 'CD']),
        'ASN': set(['CB', 'CG', 'OD1', 'ND2']),
        'ASP': set(['CB', 'CG', 'OD1', 'OD2']),
        'CYS': set(['CB', 'SG']),
        'GLN': set(['CB', 'CG', 'CD', 'NE2', 'OE1']),
        'GLU': set(['CB', 'CG', 'OE2', 'CD', 'OE1']),
        'GLY': set([]),
        'HIS': set(['CE1', 'CB', 'CG', 'CD2', 'ND1', 'NE2']),
        'ILE': set(['CB', 'CD1', 'CG1', 'CG2']),
        'LEU': set(['CB', 'CG', 'CD1', 'CD2']),
        'LYS': set(['CB', 'CG', 'NZ', 'CE', 'CD']),
        'MET': set(['CB', 'CG', 'CE', 'SD']),
        'PHE': set(['CE1', 'CB', 'CG', 'CZ', 'CD1', 'CD2', 'CE2']),
        'PRO': set(['CB', 'CG', 'CD']),
        'SER': set(['OG', 'CB']),
        'THR': set(['CB', 'OG1', 'CG2']),
        'TRP': set(['CZ2', 'CB', 'CG', 'CH2', 'CE3', 'CD1', 'CD2', 'CZ3', 'NE1', 'CE2']),
        'TYR': set(['CE1', 'OH', 'CB', 'CG', 'CZ', 'CD1', 'CD2', 'CE2']),
        'VAL': set(['CB', 'CG1', 'CG2']),
    }

    namedsele = _self.get_unused_name('_')
    _self.select(namedsele, selection, 0)

    namelists = defaultdict(list)
    _self.iterate('(%s) and polymer' % namedsele,
            'namelists[model,segi,chain,resn,resi,resv].append(name)',
            space=locals())

    sele_dict = defaultdict(list)
    tmp_name = _self.get_unused_name('_')

    for key, namelist in namelists.items():
        resn = key[3]
        if resn not in reference:
            if not quiet:
                print(' Unknown residue: + ' + resn)
            continue
        if not reference[resn].issubset(namelist):
            try:
                frag = fragments.get(resn.lower())
                for a in frag.atom:
                    a.segi = key[1]
                    a.chain = key[2]
                    a.resi = key[4]
                    a.resi_number = key[5]
                _self.load_model(frag, tmp_name, 1, zoom=0)

                skey = '/%s/%s/%s/%s`%s' % key[:5]
                _self.remove(skey + ' and not name N+C+O+OXT+CA')
                _self.align(tmp_name, skey + ' and name N+C+CA', cycles=0)
                _self.remove(tmp_name + ' and (name N+C+O+CA or hydro)')
                _self.fuse('name CB and ' + tmp_name, 'name CA and ' + skey, move=0)
                if resn == 'PRO':
                    _self.bond(skey + '/N', skey + '/CD')
                _self.unpick()
                _self.delete(tmp_name)

                sele_dict[key[0]].append(skey)

                if not quiet:
                    print(' Mutated ' + skey)
            except:
                print(' Mutating ' + skey + ' failed')

    for model in sele_dict:
        _self.sort(model)
        sculpt_relax(' '.join(sele_dict[model]), 0, 0, model, cycles)

    _self.delete(namedsele)
Ejemplo n.º 7
0
def peptide_rebuild(name, selection='all', cycles=1000, state=1, quiet=1):
    '''
DESCRIPTION

    Rebuild the peptide from selection. All atoms which are present in
    selection will be kept fixed, while atoms missing in selection are
    placed by sculpting.

USAGE

    peptide_rebuild name [, selection [, cycles [, state ]]]

SEE ALSO

    stub2ala, add_missing_atoms, peptide_rebuild_modeller
    '''
    from chempy import fragments, feedback, models

    cycles, state, quiet = int(cycles), int(state), int(quiet)

    # suppress feedback for model merging
    feedback['actions'] = False

    # work with named selection
    namedsele = cmd.get_unused_name('_')
    cmd.select(namedsele, selection, 0)

    identifiers = []
    cmd.iterate(namedsele + ' and polymer and guide and alt +A',
            'identifiers.append([segi,chain,resi,resv,resn])', space=locals())

    model = models.Indexed()
    for (segi,chain,resi,resv,resn) in identifiers:
        try:
            fname = resn.lower() if resn != 'MSE' else 'met'
            frag = fragments.get(fname)
        except IOError:
            print(' Warning: unknown residue:', resn)
            continue

        for a in frag.atom:
            a.segi = segi
            a.chain = chain
            a.resi = resi
            a.resi_number = resv
            a.resn = resn

        model.merge(frag)

    if not quiet:
        print(' Loading model...')

    cmd.load_model(model, name, 1, zoom=0)
    if cmd.get_setting_boolean('auto_remove_hydrogens'):
        cmd.remove(name + ' and hydro')

    cmd.protect(name + ' in ' + namedsele)
    cmd.sculpt_activate(name)
    cmd.update(name, namedsele, 1, state)
    cmd.delete(namedsele)

    if not quiet:
        print(' Sculpting...')

    cmd.set('sculpt_field_mask', 0x003, name) # bonds and angles only
    cmd.sculpt_iterate(name, 1, int(cycles / 4))

    cmd.set('sculpt_field_mask', 0x09F, name) # local + torsions
    cmd.sculpt_iterate(name, 1, int(cycles / 4))

    cmd.set('sculpt_field_mask', 0x0FF, name) # ... + vdw
    cmd.sculpt_iterate(name, 1, int(cycles / 2))

    cmd.sculpt_deactivate(name)
    cmd.deprotect(name)
    cmd.unset('sculpt_field_mask', name)

    if not quiet:
        print(' Connecting peptide...')

    pairs = cmd.find_pairs(name + ' and name C', name + ' and name N', 1, 1, 2.0)
    for pair in pairs:
        cmd.bond(*pair)
    cmd.h_fix(name)

    if not quiet:
        print(' peptide_rebuild: done')
Ejemplo n.º 8
0
def add_missing_atoms(selection='all', cycles=200, quiet=1):
    '''
DESCRIPTION

    Mutate those residues to themselves which have missing atoms

SEE ALSO

    stub2ala
    '''
    from collections import defaultdict
    from chempy import fragments

    cycles, quiet = int(cycles), int(quiet)

    reference = {
        'ALA': set(['CB']),
        'ARG': set(['CB', 'CG', 'NE', 'CZ', 'NH1', 'NH2', 'CD']),
        'ASN': set(['CB', 'CG', 'OD1', 'ND2']),
        'ASP': set(['CB', 'CG', 'OD1', 'OD2']),
        'CYS': set(['CB', 'SG']),
        'GLN': set(['CB', 'CG', 'CD', 'NE2', 'OE1']),
        'GLU': set(['CB', 'CG', 'OE2', 'CD', 'OE1']),
        'GLY': set([]),
        'HIS': set(['CE1', 'CB', 'CG', 'CD2', 'ND1', 'NE2']),
        'ILE': set(['CB', 'CD1', 'CG1', 'CG2']),
        'LEU': set(['CB', 'CG', 'CD1', 'CD2']),
        'LYS': set(['CB', 'CG', 'NZ', 'CE', 'CD']),
        'MET': set(['CB', 'CG', 'CE', 'SD']),
        'PHE': set(['CE1', 'CB', 'CG', 'CZ', 'CD1', 'CD2', 'CE2']),
        'PRO': set(['CB', 'CG', 'CD']),
        'SER': set(['OG', 'CB']),
        'THR': set(['CB', 'OG1', 'CG2']),
        'TRP': set(['CZ2', 'CB', 'CG', 'CH2', 'CE3', 'CD1', 'CD2', 'CZ3', 'NE1', 'CE2']),
        'TYR': set(['CE1', 'OH', 'CB', 'CG', 'CZ', 'CD1', 'CD2', 'CE2']),
        'VAL': set(['CB', 'CG1', 'CG2']),
    }

    namedsele = cmd.get_unused_name('_')
    cmd.select(namedsele, selection, 0)

    namelists = defaultdict(list)
    cmd.iterate('(%s) and polymer' % namedsele,
            'namelists[model,segi,chain,resn,resi,resv].append(name)',
            space=locals())

    sele_dict = defaultdict(list)
    tmp_name = cmd.get_unused_name('_')

    for key, namelist in namelists.items():
        resn = key[3]
        if resn not in reference:
            if not quiet:
                print(' Unknown residue:', resn)
            continue
        if not reference[resn].issubset(namelist):
            try:
                frag = fragments.get(resn.lower())
                for a in frag.atom:
                    a.segi = key[1]
                    a.chain = key[2]
                    a.resi = key[4]
                    a.resi_number = key[5]
                cmd.load_model(frag, tmp_name, 1, zoom=0)

                skey = '/%s/%s/%s/%s`%s' % key[:5]
                cmd.remove(skey + ' and not name N+C+O+OXT+CA')
                cmd.align(tmp_name, skey + ' and name N+C+CA', cycles=0)
                cmd.remove(tmp_name + ' and (name N+C+O+CA or hydro)')
                cmd.fuse('name CB and ' + tmp_name, 'name CA and ' + skey, move=0)
                if resn == 'PRO':
                    cmd.bond(skey + '/N', skey + '/CD')
                cmd.unpick()
                cmd.delete(tmp_name)

                sele_dict[key[0]].append(skey)

                if not quiet:
                    print(' Mutated ', skey)
            except:
                print(' Mutating', skey, 'failed')

    for model in sele_dict:
        cmd.sort(model)
        sculpt_relax(' '.join(sele_dict[model]), 0, 0, model, cycles)

    cmd.delete(namedsele)