Exemplo n.º 1
0
def is_atom_pair_linked(atom1,
                        atom2,
                        distance=None,
                        max_bonded_cutoff=3.,
                        amino_acid_bond_cutoff=1.9,
                        rna_dna_bond_cutoff=3.4,
                        rna_dna_angle_cutoff=35,
                        inter_residue_bond_cutoff=1.99,
                        second_row_buffer=.5,
                        metal_coordination_cutoff=3.,
                        saccharide_bond_cutoff=3.,
                        sulfur_bond_cutoff=2.5,
                        other_bond_cutoff=2., # this is the ligand distance
                        use_only_bond_cutoff=False,
                        link_metals=True,
                        verbose=False,
                        ):
  if atom1.element.strip().upper() in ad_hoc_non_linking_elements:
    return False
  if atom2.element.strip().upper() in ad_hoc_non_linking_elements:
    return False
  atom_pair = [atom1.element.strip().upper(), atom2.element.strip().upper()]
  atom_pair.sort()
  if atom_pair in ad_hoc_non_linking_pairs:
    return False
  skip_if_both = linking_setup.skip_if_both
  skip_if_longer = linking_setup.update_skip_if_longer(amino_acid_bond_cutoff,
                                                       rna_dna_bond_cutoff,
                                                       inter_residue_bond_cutoff,
                                                       saccharide_bond_cutoff,
                                                       metal_coordination_cutoff,
                                                       sulfur_bond_cutoff,
                                                       other_bond_cutoff,
                                                       )
  class1 = get_classes(atom1, important_only=True)
  class2 = get_classes(atom2, important_only=True)
  class1 = linking_setup.adjust_class(atom1, class1)
  class2 = linking_setup.adjust_class(atom2, class2)
  if ( linking_setup.sulfur_class(atom1, class1)=="sulfur" and
       linking_setup.sulfur_class(atom2, class2)=="sulfur" ):
    class1 = 'sulfur'
    class2 = 'sulfur'
  lookup = [class1, class2]
  lookup.sort()
  if verbose: print('lookup1',lookup,skip_if_both) #.get(lookup, None)
  if lookup in skip_if_both: return False
  lookup = tuple(lookup)
  if verbose: print('lookup2',lookup)
  limit = skip_if_longer.get(lookup, None)
  if limit is not None:
    if ( atom1.element not in ad_hoc_first_row or
         atom2.element not in ad_hoc_first_row):
      limit += second_row_buffer**2 # not completely accurate
  if verbose: print('limit',limit)
  if distance:
    d2 = distance**2
  else:
    d2 = get_distance2(atom1, atom2)
  if verbose: print("d2",d2)
  if limit is not None and limit<d2:
    if verbose: print('limit < d2',limit,d2)
    return False
  if use_only_bond_cutoff:
    if verbose: print('use_only_bond_cutoff',use_only_bond_cutoff)
    return True
  #
  if "common_rna_dna" in lookup and "common_amino_acid" in lookup:
    return True
  if "common_rna_dna" in lookup and "common_small_molecule" in lookup:
    return True
  if "common_amino_acid" in lookup and "common_small_molecule" in lookup:
    return True
  if "other" in lookup and "common_small_molecule" in lookup:
    return True
  #
  # sulfur bridge
  #
  if verbose:
    print(atom1.quote(),linking_setup.sulfur_class(atom1, class1))
    print(atom2.quote(),linking_setup.sulfur_class(atom2, class2))
  if ( linking_setup.sulfur_class(atom1, class1)=="sulfur" and
       linking_setup.sulfur_class(atom2, class2)=="sulfur" ):
    return True
  #
  # saccharides
  #
  if verbose: print('checking common_saccharide',lookup)
  if "common_saccharide" in lookup:
    limit = saccharide_bond_cutoff*saccharide_bond_cutoff
    if "metal" in lookup:
      limit = metal_coordination_cutoff*metal_coordination_cutoff
    if verbose: print('d2,limit',d2,limit)
    if d2>limit:
      return False
    return True
  #
  # metals
  #
  if "common_element" in lookup:
    if(atom1.element.strip().upper() in ad_hoc_single_metal_residue_element_types or
       atom2.element.strip().upper() in ad_hoc_single_metal_residue_element_types
       ):
      return True
    else:
      print('lookup',lookup)
      print(atom1.quote())
      print(atom2.quote())
      assert 0
  if "metal" in lookup:
    if not linking_setup.skip_if_non_linking(lookup, atom1, atom2):
      return False
    else:
      if link_metals:
        return is_atom_metal_coordinated(lookup, atom1, atom2)
      return link_metals
  #
  # amino acids
  #
  if class1=="common_amino_acid" and class2=="common_amino_acid":
    if verbose:
      print("AMINO ACIDS",atom1.quote(), atom2.quote())
  #
  # other
  #
  if lookup==("other", "other"):
    # non-standard residue to non-standard is too risky to do automatically ...
    if verbose: print('other, other returns True')
    return True
  elif "other" in lookup:
    if verbose: print('other returns True')
    return True
  if verbose: print('drop through '*5)
  return False
Exemplo n.º 2
0
def is_atom_pair_linked(atom1,
                        atom2,
                        distance=None,
                        max_bonded_cutoff=3.,
                        amino_acid_bond_cutoff=1.9,
                        rna_dna_bond_cutoff=3.4,
                        rna_dna_angle_cutoff=35,
                        inter_residue_bond_cutoff=1.99,
                        second_row_buffer=.5,
                        metal_coordination_cutoff=3.,
                        saccharide_bond_cutoff=3.,
                        sulfur_bond_cutoff=2.5,
                        other_bond_cutoff=2., # this is the ligand distance
                        use_only_bond_cutoff=False,
                        link_metals=True,
                        verbose=False,
                        ):
  if atom1.element.strip().upper() in ad_hoc_non_linking_elements:
    return False
  if atom2.element.strip().upper() in ad_hoc_non_linking_elements:
    return False
  atom_pair = [atom1.element.strip().upper(), atom2.element.strip().upper()]
  atom_pair.sort()
  if atom_pair in ad_hoc_non_linking_pairs:
    return False
  skip_if_both = linking_setup.skip_if_both
  skip_if_longer = linking_setup.update_skip_if_longer(amino_acid_bond_cutoff,
                                                       rna_dna_bond_cutoff,
                                                       inter_residue_bond_cutoff,
                                                       saccharide_bond_cutoff,
                                                       metal_coordination_cutoff,
                                                       sulfur_bond_cutoff,
                                                       other_bond_cutoff,
                                                       )
  class1 = get_classes(atom1, important_only=True)
  class2 = get_classes(atom2, important_only=True)
  class1 = linking_setup.adjust_class(atom1, class1)
  class2 = linking_setup.adjust_class(atom2, class2)
  if ( linking_setup.sulfur_class(atom1, class1)=="sulfur" and
       linking_setup.sulfur_class(atom2, class2)=="sulfur" ) :
    class1 = 'sulfur'
    class2 = 'sulfur'
  lookup = [class1, class2]
  lookup.sort()
  if verbose: print 'lookup1',lookup,skip_if_both #.get(lookup, None)
  if lookup in skip_if_both: return False
  lookup = tuple(lookup)
  if verbose: print 'lookup2',lookup
  limit = skip_if_longer.get(lookup, None)
  if limit is not None:
    if ( atom1.element not in ad_hoc_first_row or
         atom2.element not in ad_hoc_first_row):
      limit += second_row_buffer**2 # not completely accurate
  if verbose: print 'limit',limit
  if distance:
    d2 = distance**2
  else:
    d2 = get_distance2(atom1, atom2)
  if verbose: print "d2",d2
  if limit is not None and limit<d2:
    if verbose: print 'limit < d2',limit,d2
    return False
  if use_only_bond_cutoff:
    if verbose: print 'use_only_bond_cutoff',use_only_bond_cutoff
    return True
  #
  if "common_rna_dna" in lookup and "common_amino_acid" in lookup:
    return True
  if "common_rna_dna" in lookup and "common_small_molecule" in lookup:
    return True
  if "common_amino_acid" in lookup and "common_small_molecule" in lookup:
    return True
  if "other" in lookup and "common_small_molecule" in lookup:
    return True
  #
  # sulfur bridge
  #
  if verbose:
    print atom1.quote(),linking_setup.sulfur_class(atom1, class1)
    print atom2.quote(),linking_setup.sulfur_class(atom2, class2)
  if ( linking_setup.sulfur_class(atom1, class1)=="sulfur" and
       linking_setup.sulfur_class(atom2, class2)=="sulfur" ) :
    return True
  #
  # saccharides
  #
  if verbose: print 'checking common_saccharide',lookup
  if "common_saccharide" in lookup:
    limit = saccharide_bond_cutoff*saccharide_bond_cutoff
    if "metal" in lookup:
      limit = metal_coordination_cutoff*metal_coordination_cutoff
    if verbose: print 'd2,limit',d2,limit
    if d2>limit:
      return False
    return True
  #
  # metals
  #
  if "common_element" in lookup:
    if(atom1.element.strip().upper() in ad_hoc_single_metal_residue_element_types or
       atom2.element.strip().upper() in ad_hoc_single_metal_residue_element_types
       ):
      return True
    else:
      print 'lookup',lookup
      print atom1.quote()
      print atom2.quote()
      assert 0
  if "metal" in lookup:
    return link_metals
  #
  # amino acids
  #
  if class1=="common_amino_acid" and class2=="common_amino_acid":
    if verbose:
      print "AMINO ACIDS",atom1.quote(), atom2.quote()
  #
  # other
  #
  if lookup==("other", "other"):
    # non-standard residue to non-standard is too risky to do automatically ...
    if verbose: print 'other, other returns True'
    return True
  elif "other" in lookup:
    if verbose: print 'other returns True'
    return True
  if verbose: print 'drop through '*5
  return False