示例#1
0
 def get_missing_h_in_residue(self, residue, mon_lib_srv):
     missing = []
     ca_xyz, xyz = None, None
     mlq = rotamer_eval.mon_lib_query(residue.resname.strip().upper(),
                                      mon_lib_srv)
     if mlq is not None:
         #hd_aliases = mlq.hydrogen_deuterium_aliases()
         atom_name_list = []
         for atom in residue.atoms():
             if atom.name == " CA ":
                 ca_xyz = atom.xyz
             if (not atom.element_is_hydrogen()):
                 xyz = atom.xyz
             atom_name = atom.name.strip().upper()
             atom_name_list.append(atom_name)
             if is_deuterium(atom):
                 atom_name_list.append(atom_name.replace('D', 'H', 1))
             #if atom_name in hd_aliases:
             #  atom_name_list.append(hd_aliases[atom_name])
         if not ca_xyz:
             ca_xyz = xyz
         reference_H = []
         atom_dict = mlq.atom_dict()
         for at in atom_dict:
             reference_H.append(at)
         reference_non_H = []
         for non in mlq.non_hydrogen_atoms():
             reference_non_H.append(non.atom_id.strip().upper())
         reference_list = [
             x for x in reference_H if x not in reference_non_H
         ]
         alternative_names = [('HA1', 'HA2', 'HA3'), ('HB1', 'HB2', 'HB3'),
                              ('HG1', 'HG2', 'HG3'), ('HD1', 'HD2', 'HD3'),
                              ('HE1', 'HE2', 'HE3'),
                              ('HG11', 'HG12', 'HG13')]
         for alts in alternative_names:
             if (alts[0] in reference_list and alts[1] in reference_list):
                 if (atom_dict[alts[0]].type_energy == 'HCH2'
                         and atom_dict[alts[1]].type_energy == 'HCH2'):
                     reference_list.append(alts[2])
                     reference_list.remove(alts[0])
                     if alts[2].replace('H', 'D', 1) in atom_name_list:
                         atom_name_list.append(alts[2])
         for atom_name in reference_list:
             if atom_name not in atom_name_list:
                 if (atom_name == 'H' and
                     ('H1' in atom_name_list and 'H2' in atom_name_list
                      and 'H3' in atom_name_list)):
                     continue
                 atom_temp = atom_name.replace("*", "'")
                 if atom_name.upper() == "O1P":
                     atom_temp = "OP1"
                 elif atom_name.upper() == "O2P":
                     atom_temp = "OP2"
                 if atom_temp not in atom_name_list:
                     missing.append(atom_name)
     return xyz, missing
示例#2
0
def exercise () :
  from mmtbx.ions import server as s
  import iotbx.pdb.hierarchy
  import iotbx.pdb
  from cctbx.eltbx import chemical_elements

  # Assert that valence parameters exist for all common ions with their
  # coordinating atoms
  for elem in ["NA", "MG", "K", "CA", "MN", "FE", "NI", "CO", "CU", "ZN", "CD"]:
    params = s.get_metal_parameters(elem)
    assert (len(params.allowed_coordinating_atoms) > 0)
    assert (params.charge is not None)
    for elem2 in params.allowed_coordinating_atoms :
      atom1 = iotbx.pdb.hierarchy.atom()
      atom1.name = elem
      atom1.element = elem
      atom1.charge = "+" + str(params.charge)
      atom2 = iotbx.pdb.hierarchy.atom()
      atom2.name = elem2
      atom2.element = elem2
      atom2.charge = "{:+}".format(s.get_charge(elem2))
      assert (s.get_valence_params(atom1, atom2) != (None, None))

  # Make sure we don't crash on any ion residue names
  for elem in chemical_elements.proper_upper_list():
    s.get_element(elem)
    s.get_charge(elem)

  # Make sure we don't crash on any common residue names either
  from mmtbx import monomer_library
  from mmtbx.rotamer.rotamer_eval import mon_lib_query
  mon_lib_srv = monomer_library.server.server()
  common_residues = [getattr(iotbx.pdb, i) for i in dir(iotbx.pdb)
                     if i.startswith("common_residue_names") and
                     isinstance(getattr(iotbx.pdb, i), list)]

  common_atoms = {
    "H": -1,
    "C": 4,
    "N": -3,
    "O": -2,
    "S": -2,
    }
  for common in common_residues:
    for resn in common:
      mlq = mon_lib_query(resn, mon_lib_srv)
      if mlq is None:
        continue
      for atom in mlq.atom_dict().values():
        elem, charge = s._get_charge_params(resname = resn,
                                            element = atom.type_symbol)
        from libtbx import group_args
        class GAtom(group_args):
          def fetch_labels(self):
            return group_args(resname = self.resname)
          def id_str(self):
            return "gatom=\"{} {}\"".format(self.resname, self.element)
          def charge_as_int(self):
            return int(self.charge)
        gatom = GAtom(
          element = atom.type_symbol,
          resname = resn,
          charge = "0",
          )
        get_charge_val, get_elem_val = s.get_charge(gatom), s.get_element(gatom)
        if elem in common_atoms:
          assert charge == common_atoms[elem]
        assert get_charge_val == charge
        assert get_elem_val == elem

  # And we support all waters
  for resn in iotbx.pdb.common_residue_names_water:
    assert s.get_element(resn) == "O"
    assert s.get_charge(resn) == -2

  print "OK"
示例#3
0
def exercise():
    from mmtbx.ions import server as s
    import iotbx.pdb.hierarchy
    import iotbx.pdb
    from cctbx.eltbx import chemical_elements

    # Assert that valence parameters exist for all common ions with their
    # coordinating atoms
    for elem in [
            "NA", "MG", "K", "CA", "MN", "FE", "NI", "CO", "CU", "ZN", "CD"
    ]:
        params = s.get_metal_parameters(elem)
        assert (len(params.allowed_coordinating_atoms) > 0)
        assert (params.charge is not None)
        for elem2 in params.allowed_coordinating_atoms:
            atom1 = iotbx.pdb.hierarchy.atom()
            atom1.name = elem
            atom1.element = elem
            atom1.charge = "+" + str(params.charge)
            atom2 = iotbx.pdb.hierarchy.atom()
            atom2.name = elem2
            atom2.element = elem2
            atom2.charge = "{:+}".format(s.get_charge(elem2))
            assert (s.get_valence_params(atom1, atom2) != (None, None))

    # Make sure we don't crash on any ion residue names
    for elem in chemical_elements.proper_upper_list():
        s.get_element(elem)
        s.get_charge(elem)

    # Make sure we don't crash on any common residue names either
    from mmtbx import monomer_library
    from mmtbx.rotamer.rotamer_eval import mon_lib_query
    mon_lib_srv = monomer_library.server.server()
    common_residues = [
        getattr(iotbx.pdb, i) for i in dir(iotbx.pdb)
        if i.startswith("common_residue_names")
        and isinstance(getattr(iotbx.pdb, i), list)
    ]

    common_atoms = {
        "H": -1,
        "C": 4,
        "N": -3,
        "O": -2,
        "S": -2,
    }
    for common in common_residues:
        for resn in common:
            mlq = mon_lib_query(resn, mon_lib_srv)
            if mlq is None:
                continue
            for atom in mlq.atom_dict().values():
                elem, charge = s._get_charge_params(resname=resn,
                                                    element=atom.type_symbol)
                from libtbx import group_args

                class GAtom(group_args):
                    def fetch_labels(self):
                        return group_args(resname=self.resname)

                    def id_str(self):
                        return "gatom=\"{} {}\"".format(
                            self.resname, self.element)

                    def charge_as_int(self):
                        return int(self.charge)

                gatom = GAtom(
                    element=atom.type_symbol,
                    resname=resn,
                    charge="0",
                )
                get_charge_val, get_elem_val = s.get_charge(
                    gatom), s.get_element(gatom)
                if elem in common_atoms:
                    assert charge == common_atoms[elem]
                assert get_charge_val == charge
                assert get_elem_val == elem

    # And we support all waters
    for resn in iotbx.pdb.common_residue_names_water:
        assert s.get_element(resn) == "O"
        assert s.get_charge(resn) == -2

    print "OK"
示例#4
0
  def get_missing_h_in_residue(self, residue, mon_lib_srv):
    missing = []
    ca_xyz, xyz, xyzh = None, None, None
    mlq = rotamer_eval.mon_lib_query(residue.resname.strip().upper(), mon_lib_srv)
    if mlq is not None:
      #hd_aliases = mlq.hydrogen_deuterium_aliases()
      atom_name_list = []
      for atom in residue.atoms():
        atom_name = atom.name.strip().upper()
        if atom_name == "CA":
          ca_xyz = atom.xyz
        if (not atom.element_is_hydrogen()):
          xyz = atom.xyz
        else:
          atom_name_list.append(atom_name)
          xyzh = atom.xyz
        if is_deuterium(atom):
          atom_name_list.append(atom_name.replace('D','H',1))
        #if atom_name in hd_aliases:
        #  atom_name_list.append(hd_aliases[atom_name])
      if not ca_xyz:
        ca_xyz = xyz
      if not ca_xyz:
        ca_xyz = xyzh
      # Step 1: Get list of expected H and non-H atoms
      reference = []
      atom_dict = mlq.atom_dict()
      for at in atom_dict:
        reference.append(at)
      # Step 2: Get list of expected non-H atoms
      reference_non_H = []
      for non in mlq.non_hydrogen_atoms():
        reference_non_H.append(non.atom_id.strip().upper())
      # Step 3: Get list of expected H atoms only
      reference_hydrogens = [x for x in reference if x not in reference_non_H]
      # Step 4: There can be naming differences: HB1+HB2 or HB2+HB3
      alternative_names = [
        ('HA1', 'HA2', 'HA3'),
        ('HB1', 'HB2', 'HB3'),
        ('HG1', 'HG2', 'HG3'),
        ('HD1', 'HD2', 'HD3'),
        ('HE1', 'HE2', 'HE3'),
        ('HG11', 'HG12', 'HG13')
        ]
      for alts in alternative_names:
        if (alts[0] in reference_hydrogens and alts[1] in reference_hydrogens):
          if (atom_dict[alts[0]].type_energy == 'HCH2' and
              atom_dict[alts[1]].type_energy == 'HCH2'):
            reference_hydrogens.append(alts[2])
            reference_hydrogens.remove(alts[0])
#            if alts[2].replace('H','D',1) in atom_name_list:
#              atom_name_list.append(alts[2])
      for atom_name in reference_hydrogens:
        if atom_name not in atom_name_list:
          if (atom_name == 'H' and
            ('H1' in atom_name_list and 'H2' in atom_name_list and 'H3' in atom_name_list)):
            continue
          if (atom_name.endswith('*')):
            atom_temp = atom_name.replace("*", "'")
          elif (atom_name.endswith('*1')):
            atom_temp = atom_name.replace("*1", "'")
          elif (atom_name.endswith('*2')):
            atom_temp = atom_name.replace("*2", "''")
          else:
            atom_temp = atom_name

#          if atom_name.upper() == "O1P":
#            atom_temp = "OP1"
#          elif atom_name.upper() == "O2P":
#            atom_temp = "OP2"
          if atom_temp not in atom_name_list:
            if atom_temp.endswith("'"):
              missing.append(atom_temp)
            else:
              missing.append(atom_name)
    return ca_xyz, missing