Exemplo n.º 1
0
def _parse_atom_site_openbabel(parsed):
    """Parse _atom_site record to OBMolecule

    Args:
        parsed (dict of str): Parsed mmcif file.

    Returns:
        [OBMol]: openbabel representation of the protein structure.
    """
    perceived_atom_site = parsed["_atom_site"]
    atom_site = _trim_models(perceived_atom_site)

    table = ob.OBElementTable()
    last_res_id = None
    last_res_name = None
    last_chain_id = None
    chain_num = 0
    res = None

    mol = ob.OBMol()
    mol.SetChainsPerceived()
    mol.BeginModify()

    for i in range(len(atom_site["id"])):
        current_res_id = _get_res_id(atom_site, i)
        ins_code = _get_ins_code(atom_site, i)

        if last_chain_id != atom_site["auth_asym_id"][i]:
            chain_num += 1
            last_chain_id = atom_site["auth_asym_id"][i]

        if (current_res_id != last_res_id
                or atom_site["auth_asym_id"][i] != last_chain_id
                or atom_site["label_comp_id"][i] != last_res_name):

            last_res_id = current_res_id
            last_res_name = atom_site["label_comp_id"][i]

            res = mol.NewResidue()
            res.SetChainNum(chain_num)
            res.SetNum(str(last_res_id))
            res.SetName(atom_site["label_comp_id"][i])
            res.SetInsertionCode(ins_code)

        _init_openbabel_atom(table, mol, res, atom_site, i)

    resdat = ob.OBResidueData()
    resdat.AssignBonds(mol, ob.OBBitVec())
    mol.ConnectTheDots()
    mol.PerceiveBondOrders()

    if "_struct_conn" in parsed:
        parse_struct_conn_bonds(mol, parsed)

    mol.EndModify()

    return mol
Exemplo n.º 2
0
def gen_canonicallabels(poltype,mol):
    poltype.symmetryclass = [ 0 ] * mol.NumAtoms()
    """
    Intent: Find the symmetry class that each atom belongs to
    Input: 
        mol: OBMol object 
    Output: 
        The global variable 'symmetryclass' is altered
    Referenced By: main
    Description:
    1. An empty bit vector is created, 'frag_atoms'
    2. OBMol.FindLargestFragment is called to fill in the 'frag_atoms' bit vector (the
    vector is filled with a 1 or 0 depending on whether the atom is part of the largest
    fragment or not)
    3. 'CalculateSymmetry' method is called to find initial symmetry classes
    4. Terminal atoms of the same element are collapsed to one symmetry class
    5. Possibly renumber the symmetry classes
    """
    # Returns symmetry classes for each atom ID
    frag_atoms = openbabel.OBBitVec()
    symmclasslist = []
    mol.FindLargestFragment(frag_atoms)
    CalculateSymmetry(poltype,mol, frag_atoms, symmclasslist)
    for ii in range(len(poltype.symmetryclass)):
        poltype.symmetryclass[ii] = symmclasslist[ii][1]

    # Collapse terminal atoms of same element to one type
    for a in openbabel.OBMolAtomIter(mol):
        for b in openbabel.OBAtomAtomIter(a):
            if b.GetValence() == 1:
                for c in openbabel.OBAtomAtomIter(a):
                    if ((b is not c) and
                        (c.GetValence() == 1) and
                        (b.GetAtomicNum() == c.GetAtomicNum()) and
                        (poltype.symmetryclass[b.GetIdx()-1] !=
                            poltype.symmetryclass[c.GetIdx()-1])):
                        poltype.symmetryclass[c.GetIdx()-1] = \
                            poltype.symmetryclass[b.GetIdx()-1]

    # Renumber symmetry classes
    allcls=list(set(poltype.symmetryclass))
    allcls.sort()
    for ii in range(len(poltype.symmetryclass)):
        poltype.symmetryclass[ii] = allcls.index(poltype.symmetryclass[ii]) + 1
Exemplo n.º 3
0
 def createBitVec(self, size, bits):
     bv = ob.OBBitVec(size)
     for bit in bits:
         bv.SetBitOn(bit)
     return bv