예제 #1
0
def get_mmtfstr(selection='all', state=1, _self=cmd):
    '''
DESCRIPTION

    DEPRECATED: Use cmd.get_bytes('mmtf')

    Export an atom selection to MMTF format.
    '''
    import simplemmtf

    try:
        # register PyMOL-specific spec extensions
        simplemmtf.levels[u'atom'][u'pymolReps'] = 0
        simplemmtf.levels[u'atom'][u'pymolColor'] = 0
        simplemmtf.encodingrules[u'pymolRepsList'] = (7, 0)
    except Exception as e:
        print(e)

    mmtfstr = simplemmtf.mmtfstr

    ss_map = {
        'H': 2,  # alpha helix
        'S': 3,  # extended
    }

    def callback(state, segi, chain, resv, resi, resn, name, elem, x, y, z,
                 reps, color, alt, formal_charge, b, q, ss):
        atoms.append({
            u'modelIndex': state,
            u'chainId': mmtfstr(segi),
            u'chainName': mmtfstr(chain),
            u'groupId': resv,
            u'groupName': mmtfstr(resn),
            u'atomName': mmtfstr(name),
            u'element': mmtfstr(elem),
            u'coords': (x, y, z),
            u'altLoc': mmtfstr(alt),
            u'formalCharge': formal_charge,
            u'bFactor': b,
            u'occupancy': q,
            u'secStruct': ss_map.get(ss, -1),
            u'insCode': mmtfstr(resi.lstrip('0123456789')),
            u'pymolReps': reps,
            u'pymolColor': color,
        })

    atoms = []
    _self.iterate_state(
        state,
        selection,
        'callback(state, segi, chain, resv, resi, resn, name, elem, '
        'x, y, z, reps, color, alt, formal_charge, b, q, ss)',
        space={'callback': callback})

    bonds = _self.get_bonds(selection, state)

    d_out = simplemmtf.from_atoms(atoms, bonds)

    return d_out.encode()
예제 #2
0
def get_mmtfstr(selection='all', state=1, _self=cmd):
    '''
DESCRIPTION

    DEPRECATED: Use cmd.get_bytes('mmtf')

    Export an atom selection to MMTF format.
    '''
    import simplemmtf

    try:
        # register PyMOL-specific spec extensions
        simplemmtf.levels[u'atom'][u'pymolReps'] = 0
        simplemmtf.levels[u'atom'][u'pymolColor'] = 0
        simplemmtf.encodingrules[u'pymolRepsList'] = (7, 0)
    except Exception as e:
        print(e)

    mmtfstr = simplemmtf.mmtfstr

    ss_map = {
        'H': 2,  # alpha helix
        'S': 3,  # extended
    }

    def callback(state, segi, chain, resv, resi, resn, name, elem,
            x, y, z, reps, color, alt, formal_charge, b, q, ss):
        atoms.append({
            u'modelIndex': state,
            u'chainId': mmtfstr(segi),
            u'chainName': mmtfstr(chain),
            u'groupId': resv,
            u'groupName': mmtfstr(resn),
            u'atomName': mmtfstr(name),
            u'element': mmtfstr(elem),
            u'coords': (x, y, z),
            u'altLoc': mmtfstr(alt),
            u'formalCharge': formal_charge,
            u'bFactor': b,
            u'occupancy': q,
            u'secStruct': ss_map.get(ss, -1),
            u'insCode': mmtfstr(resi.lstrip('0123456789')),
            u'pymolReps': reps,
            u'pymolColor': color,
        })

    atoms = []
    _self.iterate_state(state, selection,
            'callback(state, segi, chain, resv, resi, resn, name, elem, '
            'x, y, z, reps, color, alt, formal_charge, b, q, ss)',
            space={'callback': callback})

    bonds = _self.get_bonds(selection, state)

    d_out = simplemmtf.from_atoms(atoms, bonds)

    return d_out.encode()
예제 #3
0
def test_encodable():
    atoms = [{
        u'atomName': u'N',
        u'chainId': u'A',
        u'coords': (12.284, 42.763, 10.037),
        u'element': u'N',
        u'groupName': u'MET',
    }]

    # len('A') <= 4: encodable -> binary
    d = simplemmtf.from_atoms(atoms)
    assert d.get(u'chainIdList') == ['A']
    assert isinstance(d._data[u'chainIdList'], bytes)

    atoms[0][u'chainId'] = u'ABCDE'

    # len('ABCDE') > 4: not encodable -> array
    d = simplemmtf.from_atoms(atoms)
    assert d.get(u'chainIdList') == ['ABCDE']
    assert isinstance(d._data[u'chainIdList'], list)
예제 #4
0
def pdb2mmtf(handle):
    '''
    @type handle: open file handle for reading
    @rtype: bytes
    '''

    from simplemmtf import mmtfstr, from_atoms

    def atom_gen():
        state = 0

        for line in handle:
            rec = line[:6]

            if rec == 'MODEL ':
                state += 1
            elif rec in ('ATOM  ', 'HETATM'):
                yield {
                    u'modelIndex': state,
                    u'atomId': int(line[6:11]),
                    u'atomName': mmtfstr(line[12:16].strip()),
                    u'altLoc': mmtfstr(line[16:17].rstrip()),
                    u'groupName': mmtfstr(line[17:20].strip()),
                    u'chainName': mmtfstr(line[21:22].rstrip()),
                    u'groupId': int(line[22:26]),
                    u'insCode': mmtfstr(line[26:27].rstrip()),
                    u'xCoord': float(line[30:38]),
                    u'yCoord': float(line[38:46]),
                    u'zCoord': float(line[46:54]),
                    u'bFactor': float(line[60:66]),
                    u'occupancy': float(line[54:60]),
                    u'chainId': mmtfstr(line[72:76].strip()),
                    u'element': mmtfstr(line[76:78].lstrip()),
                }

    d_out = from_atoms(atom_gen())

    return d_out.encode()
def get_mmtfstr(selection='all', state=1, _self=pymol.cmd):
    '''
DESCRIPTION

    Get an atom selection as MMTF format.
    '''
    from simplemmtf import mmtfstr, from_atoms

    state = int(state)

    if state == 0:
        states = range(1, _self.count_states(selection) + 1)
    else:
        states = [state]

    ss_map = {
        'H': 2,  # alpha helix
        'S': 3,  # extended
    }

    bonds = []
    atoms = []

    if True:
        numBonds = 0

        for state in states:
            m = _self.get_model(selection, state)

            for a in m.atom:
                atom = {
                    u'modelIndex': state,
                    u'chainId': mmtfstr(a.segi),
                    u'chainName': mmtfstr(a.chain),
                    u'groupId': a.resi_number,
                    u'groupName': mmtfstr(a.resn),
                    u'atomName': mmtfstr(a.name),
                    u'element': mmtfstr(a.symbol),
                    u'coords': a.coord,
                }

                if a.resi[-1:].isalpha():
                    atom[u'insCode'] = mmtfstr(a.resi[-1])

                if a.alt:
                    atom[u'altLoc'] = mmtfstr(a.alt)

                if a.formal_charge:
                    atom[u'formalCharge'] = int(a.formal_charge)

                if a.b:
                    atom[u'bFactor'] = a.b

                if a.q != 1.0:
                    atom[u'occupancy'] = a.q

                if a.ss:
                    atom[u'secStruct'] = ss_map.get(a.ss, -1)

                atoms.append(atom)

            for b in m.bond:
                bonds.append(
                    (b.index[0] + numBonds, b.index[1] + numBonds, b.order))

            numBonds += len(m.atom)

    d_out = from_atoms(atoms, bonds)

    return d_out.encode()