def angles(O):
   return graph_utils.extract_edge_list(
     graph_utils.bond_bending_edge_sets(
       edge_sets=graph_utils.construct_edge_sets(
         n_vertices=len(O.sites),
         edge_list=O.bonds),
       omit_bonds=True))
Exemple #2
0
 def angles(O):
     return graph_utils.extract_edge_list(
         graph_utils.bond_bending_edge_sets(
             edge_sets=graph_utils.construct_edge_sets(n_vertices=len(
                 O.sites),
                                                       edge_list=O.bonds),
             omit_bonds=True))
Exemple #3
0
 def process(file_name, clash_threshold=2.0):
   time_start = time.time()
   pdb_inp = iotbx.pdb.input(file_name=file_name)
   pdb_atoms = pdb_inp.atoms()
   print "Time reading pdb file: %.2f" % (time.time() - time_start)
   print "Number of atoms:", pdb_atoms.size()
   pdb_atoms.set_chemical_element_simple_if_necessary()
   sites_cart = pdb_atoms.extract_xyz()
   #
   time_start = time.time()
   bond_list = extract_edge_list(edge_sets=build_simple_two_way_bond_sets(
     sites_cart=sites_cart,
     elements=pdb_atoms.extract_element()))
   print "Time building bond list: %.2f" % (time.time() - time_start)
   print "Number of bonds:", len(bond_list)
   #
   time_start = time.time()
   tardy_tree = scitbx.graph.tardy_tree.construct(
     sites=sites_cart,
     edge_list=bond_list)
   print "Time building tardy tree: %.2f" % (time.time() - time_start)
   #
   time_start = time.time()
   tardy_model = scitbx.rigid_body.tardy_model(
     labels=[atom.id_str() for atom in pdb_atoms],
     sites=sites_cart,
     masses=[1]*sites_cart.size(),
     tardy_tree=tardy_tree,
     potential_obj=None)
   q_size_each_joint = tardy_model.q_size_each_joint()
   q_fixed = tardy_model.pack_q()[:q_size_each_joint[0]]
   assert q_size_each_joint[1:].all_eq(1) # must all be revolute joints
   q_size_moving = q_size_each_joint.size() - 1
   print "Time building tardy model: %.2f" % (time.time() - time_start)
   print "Degrees of freedom:", q_size_moving
   #
   mt = flex.mersenne_twister()
   two_pi = 2 * math.pi
   clash_detector = build_clash_detector(
     n_sites=sites_cart.size(),
     bond_list=bond_list,
     threshold=clash_threshold)
   time_start = time.time()
   n_conf = 10000
   n_clash_conf = 0
   for i_conf in xrange(n_conf):
     q = q_fixed.deep_copy()
     q.extend(mt.random_double(size=q_size_moving)*two_pi)
     tardy_model.unpack_q(q_packed=q)
     conf_sites_cart = tardy_model.sites_moved()
     if (clash_detector.has_clash(sites_cart=conf_sites_cart)):
       n_clash_conf += 1
   time_diff = time.time() - time_start
   print "time / %d conf: %.2f seconds" % (n_conf, time_diff)
   print "time / conf: %.3f milli seconds" % (time_diff / n_conf * 1000)
   if (time_diff != 0):
     print "conf / second: %.2f" % (n_conf / time_diff)
   print "Fraction of conformations with clashes: %d / %d = %.2f %%" % (
     n_clash_conf, n_conf, 100. * n_clash_conf / n_conf)
def arch_dof(n_vertices, edge_list):
  es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=edge_list)
  bbes = utils.bond_bending_edge_sets(edge_sets=es)
  bbel = utils.extract_edge_list(edge_sets=bbes)
  dofs = [rigidity.determine_degrees_of_freedom(
    n_dim=3, n_vertices=n_vertices, edge_list=bbel, method=method)
      for method in ["float", "integer"]]
  assert dofs[0] == dofs[1]
  return es, dofs[0]
def arch_dof(n_vertices, edge_list):
  es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=edge_list)
  bbes = utils.bond_bending_edge_sets(edge_sets=es)
  bbel = utils.extract_edge_list(edge_sets=bbes)
  dofs = [rigidity.determine_degrees_of_freedom(
    n_dim=3, n_vertices=n_vertices, edge_list=bbel, method=method)
      for method in ["float", "integer"]]
  assert dofs[0] == dofs[1]
  return es, dofs[0]
Exemple #6
0
 def find_cluster_loops(O):
   assert O.find_cluster_loop_repeats is None
   if (O.edge_sets is None):
     O.find_cluster_loop_repeats = 0
     return
   O.find_cluster_loop_repeats = -1
   cm = O.cluster_manager
   while True:
     O.find_cluster_loop_repeats += 1
     cm.merge_clusters_with_multiple_connections(edge_sets=O.edge_sets)
     ces = cm.cluster_edge_sets(edge_list=O.edge_list)
     cel = extract_edge_list(edge_sets=ces)
     ctt = construct(n_vertices=len(cm.clusters), edge_list=cel)
     ccm = ctt.cluster_manager
     ccm.merge_clusters_with_multiple_connections(edge_sets=ctt.edge_sets)
     if (len(ccm.clusters) == len(cm.clusters)):
       break
     for cc in ccm.clusters:
       cii = cc[0]
       for cij in cc[1:]:
         cii = cm.connect_clusters(cii=cii, cij=cij, optimize=True)
     cm.tidy()
   return O
Exemple #7
0
 def find_cluster_loops(O):
     assert O.find_cluster_loop_repeats is None
     if (O.edge_sets is None):
         O.find_cluster_loop_repeats = 0
         return
     O.find_cluster_loop_repeats = -1
     cm = O.cluster_manager
     while True:
         O.find_cluster_loop_repeats += 1
         cm.merge_clusters_with_multiple_connections(edge_sets=O.edge_sets)
         ces = cm.cluster_edge_sets(edge_list=O.edge_list)
         cel = extract_edge_list(edge_sets=ces)
         ctt = construct(n_vertices=len(cm.clusters), edge_list=cel)
         ccm = ctt.cluster_manager
         ccm.merge_clusters_with_multiple_connections(
             edge_sets=ctt.edge_sets)
         if (len(ccm.clusters) == len(cm.clusters)):
             break
         for cc in ccm.clusters:
             cii = cc[0]
             for cij in cc[1:]:
                 cii = cm.connect_clusters(cii=cii, cij=cij, optimize=True)
         cm.tidy()
     return O
Exemple #8
0
 def extract_edge_list(O):
     return extract_edge_list(edge_sets=O.edge_sets)
Exemple #9
0
def run(args):
  assert len(args) == 0
  #
  el = []
  n_vertices = 0
  es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
  assert len(es) == 0
  bbes = utils.bond_bending_edge_sets(edge_sets=es)
  assert len(bbes) == 0
  bbel = utils.extract_edge_list(edge_sets=bbes)
  assert len(bbel) == 0
  piel = utils.potential_implied_edge_list(
    edge_sets=es, bond_bending_edge_sets=bbes)
  assert len(piel) == 0
  bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
  assert len(bbesob) == 0
  #
  el = [(0,1), (1,2), (2,3)]
  n_vertices = 4
  es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
  assert len(es) == n_vertices
  bbes = utils.bond_bending_edge_sets(edge_sets=es)
  assert len(bbes) == n_vertices
  bbel = utils.extract_edge_list(edge_sets=bbes)
  assert bbel == [(0,1), (0,2), (1,2), (1,3), (2,3)]
  assert set(el).issubset(set(bbel))
  piel = utils.potential_implied_edge_list(
    edge_sets=es, bond_bending_edge_sets=bbes)
  assert piel == [(0,3)]
  assert set(bbel).isdisjoint(set(piel))
  bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
  assert len(bbesob) == n_vertices
  bbelob = utils.extract_edge_list(edge_sets=bbesob)
  assert bbelob == [(0,2), (1,3)]
  #
  el = [(0,1), (1,2), (2,3), (3,4), (4,5), (5,6), (6,7)]
  n_vertices = 8
  es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
  bbes = utils.bond_bending_edge_sets(edge_sets=es)
  bbel = utils.extract_edge_list(edge_sets=bbes)
  assert bbel == [
    (0, 1), (0, 2),
    (1, 2), (1, 3),
    (2, 3), (2, 4),
    (3, 4), (3, 5),
    (4, 5), (4, 6),
    (5, 6), (5, 7),
    (6, 7)]
  assert set(el).issubset(set(bbel))
  piel = utils.potential_implied_edge_list(
    edge_sets=es, bond_bending_edge_sets=bbes)
  assert piel == [(0,3), (1,4), (2,5), (3,6), (4,7)]
  assert set(bbel).isdisjoint(set(piel))
  bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
  bbelob = utils.extract_edge_list(edge_sets=bbesob)
  assert bbelob == [
    (0, 2),
    (1, 3),
    (2, 4),
    (3, 5),
    (4, 6),
    (5, 7)]
  #
  el = [(0,1), (1,2), (2,3), (0,3)]
  n_vertices = 4
  es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
  bbes = utils.bond_bending_edge_sets(edge_sets=es)
  bbel = utils.extract_edge_list(edge_sets=bbes)
  assert bbel == [(0,1), (0,2), (0,3), (1,2), (1,3), (2,3)]
  assert set(el).issubset(set(bbel))
  piel = utils.potential_implied_edge_list(
    edge_sets=es, bond_bending_edge_sets=bbes)
  assert piel == []
  bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
  bbelob = utils.extract_edge_list(edge_sets=bbesob)
  assert bbelob == [(0, 2), (1, 3)]
  #
  el = [(0,1), (1,2), (2,3), (3,4), (4,5), (0,5)]
  n_vertices = 6
  es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
  bbes = utils.bond_bending_edge_sets(edge_sets=es)
  bbel = utils.extract_edge_list(edge_sets=bbes)
  assert bbel == [
    (0,1), (0,2), (0,4), (0,5),
    (1,2), (1,3), (1,5),
    (2,3), (2,4),
    (3,4), (3,5),
    (4,5)]
  assert set(el).issubset(set(bbel))
  piel = utils.potential_implied_edge_list(
    edge_sets=es, bond_bending_edge_sets=bbes)
  assert piel == [(0,3), (1,4), (2,5)]
  assert set(bbel).isdisjoint(set(piel))
  bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
  bbelob = utils.extract_edge_list(edge_sets=bbesob)
  assert bbelob == [
    (0,2), (0,4),
    (1,3), (1,5),
    (2,4),
    (3,5)]
  #
  el = [(0,1), (1,2), (2,3), (2,6), (3,4), (3,7), (4,5), (0,5)]
  n_vertices = 8
  es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
  bbes = utils.bond_bending_edge_sets(edge_sets=es)
  bbel = utils.extract_edge_list(edge_sets=bbes)
  assert bbel == [
    (0,1), (0,2), (0,4), (0,5),
    (1,2), (1,3), (1,5), (1,6),
    (2,3), (2,4), (2,6), (2,7),
    (3,4), (3,5), (3,6), (3,7),
    (4,5), (4,7)]
  assert set(el).issubset(set(bbel))
  piel = utils.potential_implied_edge_list(
    edge_sets=es, bond_bending_edge_sets=bbes)
  assert piel == [(0,3), (0,6), (1,4), (1,7), (2,5), (4,6), (5,7), (6,7)]
  assert set(bbel).isdisjoint(set(piel))
  bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
  bbelob = utils.extract_edge_list(edge_sets=bbesob)
  assert bbelob == [
    (0,2), (0,4),
    (1,3), (1,5), (1,6),
    (2,4), (2,7),
    (3,5), (3,6),
    (4,7)]
  #
  el = [(0,1), (1,2), (2,3), (2,6), (3,4), (3,7), (4,5), (0,5)]
  n_vertices = 8
  es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
  sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[])
  assert len(sub.edge_list) == 0
  assert len(sub.edge_sets()) == 0
  sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[1])
  assert len(sub.edge_list) == 0
  assert len(sub.edge_sets()) == 1
  sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[1,3])
  assert len(sub.edge_list) == 0
  assert len(sub.edge_sets()) == 2
  sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[1,0])
  assert sub.edge_list == [(0,1)]
  assert len(sub.edge_sets()) == 2
  assert sub.reindexing_dict == {0: 1, 1: 0}
  sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[6,7,3,2])
  assert sub.edge_list == [(1,2), (2,3), (0,3)]
  assert len(sub.edge_sets()) == 4
  assert sub.reindexing_dict == {2: 3, 3: 2, 6: 0, 7: 1}
  #
  exercise_tree_marking()
  #
  print "OK"
Exemple #10
0
 def extract_edge_list(O):
   return extract_edge_list(edge_sets=O.edge_sets)
Exemple #11
0
def run(args):
    assert len(args) == 0
    #
    el = []
    n_vertices = 0
    es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
    assert len(es) == 0
    bbes = utils.bond_bending_edge_sets(edge_sets=es)
    assert len(bbes) == 0
    bbel = utils.extract_edge_list(edge_sets=bbes)
    assert len(bbel) == 0
    piel = utils.potential_implied_edge_list(edge_sets=es,
                                             bond_bending_edge_sets=bbes)
    assert len(piel) == 0
    bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
    assert len(bbesob) == 0
    #
    el = [(0, 1), (1, 2), (2, 3)]
    n_vertices = 4
    es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
    assert len(es) == n_vertices
    bbes = utils.bond_bending_edge_sets(edge_sets=es)
    assert len(bbes) == n_vertices
    bbel = utils.extract_edge_list(edge_sets=bbes)
    assert bbel == [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3)]
    assert set(el).issubset(set(bbel))
    piel = utils.potential_implied_edge_list(edge_sets=es,
                                             bond_bending_edge_sets=bbes)
    assert piel == [(0, 3)]
    assert set(bbel).isdisjoint(set(piel))
    bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
    assert len(bbesob) == n_vertices
    bbelob = utils.extract_edge_list(edge_sets=bbesob)
    assert bbelob == [(0, 2), (1, 3)]
    #
    el = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7)]
    n_vertices = 8
    es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
    bbes = utils.bond_bending_edge_sets(edge_sets=es)
    bbel = utils.extract_edge_list(edge_sets=bbes)
    assert bbel == [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (2, 4), (3, 4),
                    (3, 5), (4, 5), (4, 6), (5, 6), (5, 7), (6, 7)]
    assert set(el).issubset(set(bbel))
    piel = utils.potential_implied_edge_list(edge_sets=es,
                                             bond_bending_edge_sets=bbes)
    assert piel == [(0, 3), (1, 4), (2, 5), (3, 6), (4, 7)]
    assert set(bbel).isdisjoint(set(piel))
    bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
    bbelob = utils.extract_edge_list(edge_sets=bbesob)
    assert bbelob == [(0, 2), (1, 3), (2, 4), (3, 5), (4, 6), (5, 7)]
    #
    el = [(0, 1), (1, 2), (2, 3), (0, 3)]
    n_vertices = 4
    es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
    bbes = utils.bond_bending_edge_sets(edge_sets=es)
    bbel = utils.extract_edge_list(edge_sets=bbes)
    assert bbel == [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
    assert set(el).issubset(set(bbel))
    piel = utils.potential_implied_edge_list(edge_sets=es,
                                             bond_bending_edge_sets=bbes)
    assert piel == []
    bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
    bbelob = utils.extract_edge_list(edge_sets=bbesob)
    assert bbelob == [(0, 2), (1, 3)]
    #
    el = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (0, 5)]
    n_vertices = 6
    es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
    bbes = utils.bond_bending_edge_sets(edge_sets=es)
    bbel = utils.extract_edge_list(edge_sets=bbes)
    assert bbel == [(0, 1), (0, 2), (0, 4), (0, 5), (1, 2), (1, 3), (1, 5),
                    (2, 3), (2, 4), (3, 4), (3, 5), (4, 5)]
    assert set(el).issubset(set(bbel))
    piel = utils.potential_implied_edge_list(edge_sets=es,
                                             bond_bending_edge_sets=bbes)
    assert piel == [(0, 3), (1, 4), (2, 5)]
    assert set(bbel).isdisjoint(set(piel))
    bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
    bbelob = utils.extract_edge_list(edge_sets=bbesob)
    assert bbelob == [(0, 2), (0, 4), (1, 3), (1, 5), (2, 4), (3, 5)]
    #
    el = [(0, 1), (1, 2), (2, 3), (2, 6), (3, 4), (3, 7), (4, 5), (0, 5)]
    n_vertices = 8
    es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
    bbes = utils.bond_bending_edge_sets(edge_sets=es)
    bbel = utils.extract_edge_list(edge_sets=bbes)
    assert bbel == [(0, 1), (0, 2), (0, 4), (0, 5), (1, 2), (1, 3), (1, 5),
                    (1, 6), (2, 3), (2, 4), (2, 6), (2, 7), (3, 4), (3, 5),
                    (3, 6), (3, 7), (4, 5), (4, 7)]
    assert set(el).issubset(set(bbel))
    piel = utils.potential_implied_edge_list(edge_sets=es,
                                             bond_bending_edge_sets=bbes)
    assert piel == [(0, 3), (0, 6), (1, 4), (1, 7), (2, 5), (4, 6), (5, 7),
                    (6, 7)]
    assert set(bbel).isdisjoint(set(piel))
    bbesob = utils.bond_bending_edge_sets(edge_sets=es, omit_bonds=True)
    bbelob = utils.extract_edge_list(edge_sets=bbesob)
    assert bbelob == [(0, 2), (0, 4), (1, 3), (1, 5), (1, 6), (2, 4), (2, 7),
                      (3, 5), (3, 6), (4, 7)]
    #
    el = [(0, 1), (1, 2), (2, 3), (2, 6), (3, 4), (3, 7), (4, 5), (0, 5)]
    n_vertices = 8
    es = utils.construct_edge_sets(n_vertices=n_vertices, edge_list=el)
    sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[])
    assert len(sub.edge_list) == 0
    assert len(sub.edge_sets()) == 0
    sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[1])
    assert len(sub.edge_list) == 0
    assert len(sub.edge_sets()) == 1
    sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[1, 3])
    assert len(sub.edge_list) == 0
    assert len(sub.edge_sets()) == 2
    sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[1, 0])
    assert sub.edge_list == [(0, 1)]
    assert len(sub.edge_sets()) == 2
    assert sub.reindexing_dict == {0: 1, 1: 0}
    sub = utils.sub_edge_list(edge_sets=es, vertex_indices=[6, 7, 3, 2])
    assert sub.edge_list == [(1, 2), (2, 3), (0, 3)]
    assert len(sub.edge_sets()) == 4
    assert sub.reindexing_dict == {2: 3, 3: 2, 6: 0, 7: 1}
    #
    exercise_tree_marking()
    #
    print("OK")