def run(args):
  assert len(args) == 0
  from cctbx.crystal.distance_based_connectivity import \
    build_simple_two_way_bond_sets
  from scitbx.array_family import flex
  sites_cart = flex.vec3_double([
    (25.655, 43.266, 42.630),
    (24.038, 43.853, 43.337),
    (23.048, 44.525, 43.290),
    (21.223, 44.207, 41.475),
    (24.951, 47.170, 37.585),
    (19.298, 46.942, 51.808)])
  elements = flex.std_string(["S", "C", "N", "CU", "ZN", "CA"])
  bond_list = build_simple_two_way_bond_sets(
    sites_cart=sites_cart, elements=elements)
  assert [sorted(b) for b in bond_list] == [[1], [0,2], [1,3], [2], [], []]
  #
  # caffeine
  sites_cart = flex.vec3_double([
    (-2.986, 0.015, 1.643),
    (-1.545, 0.015, 1.643),
    (-0.733, 0.015, 2.801),
    (0.592, 0.015, 2.395),
    (0.618, 0.015, 1.034),
    (1.758, 0.015, 0.102),
    (3.092, -0.06, 0.694),
    (1.525, 0.015, -1.360),
    (2.489, -0.024, -2.139),
    (0.158, 0.015, -1.888),
    (-0.025, 0.024, -3.330),
    (-0.986, 0.015, -0.959),
    (-2.155, 0.008, -1.408),
    (-0.733, 0.015, 0.565),
    (-3.346, 0.016, 2.662),
    (-3.347, 0.896, 1.133),
    (-3.347, -0.868, 1.136),
    (-1.083, 0.02, 3.822),
    (3.184, -0.975, 1.26),
    (3.245, 0.785, 1.348),
    (3.835, -0.047, -0.09),
    (0.508, 0.861, -3.756),
    (-1.076, 0.113, -3.560),
    (0.358, -0.896, -3.748)
  ])
  elements = flex.std_string([
    ' C', ' N', ' C', ' N', ' C', ' N', ' C', ' C', ' O', ' N', ' C', ' C',
    ' O', ' C', ' H', ' H', ' H', ' H', ' H', ' H', ' H', ' H', ' H', ' H'])
  bonds = build_simple_two_way_bond_sets(
    sites_cart=sites_cart, elements=elements)
  assert bonds.size() == sites_cart.size()
  assert list(bonds[0]) == [1, 14, 15, 16]
  #
  print "OK"
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
 def set_points_and_lines(O, app, minimum_covering_sphere_view_scale=1.3):
     pdb_atoms = app.pdb_atoms
     pdb_atoms.set_chemical_element_simple_if_necessary()
     atom_tmp_sentinel = pdb_atoms.reset_tmp(first_value=0, increment=0)
     for i, rg in enumerate(app.pdb_hierarchy.residue_groups()):
         for atom in rg.atoms():
             atom.tmp = i
     O.points = pdb_atoms.extract_xyz()
     if (app.co.serial_labels):
         m = ""
         need_m = (app.pdb_hierarchy.models_size() != 1)
         for mdl in app.pdb_hierarchy.models():
             if (need_m): m = mdl.id.strip() + ":"
             for i in range(mdl.atoms_size()):
                 O.labels.append(m + str(i))
         assert len(O.labels) == O.points.size()
     else:
         rg_done = set()
         for atom in pdb_atoms:
             i = atom.tmp
             if (i not in rg_done):
                 rg_done.add(i)
                 l = atom.id_str()
             else:
                 l = atom.name
             O.labels.append(l)
     from cctbx.crystal.distance_based_connectivity import \
       build_simple_two_way_bond_sets
     bond_sets = build_simple_two_way_bond_sets(
         sites_cart=O.points, elements=pdb_atoms.extract_element())
     for i, bond_set in enumerate(bond_sets):
         for j in bond_set:
             if (i < j):
                 line = (i, j)
                 ai, aj = [pdb_atoms[_] for _ in line]
                 if (ai.is_in_same_conformer_as(aj)):
                     O.line_i_seqs.append(line)
                     if (ai.tmp == aj.tmp):
                         if (ai.tmp % 2 == 0):
                             color = (0, 0, 1)
                         else:
                             color = (0, 1, 0)
                     else:
                         color = (1, 0, 0)
                     O.line_colors[line] = color
     del atom_tmp_sentinel
     from scitbx.math import minimum_covering_sphere, sphere_3d
     mcs = minimum_covering_sphere(O.points, epsilon=1.e-2)
     O.minimum_covering_sphere = sphere_3d(
         center=mcs.center(),
         radius=mcs.radius() * minimum_covering_sphere_view_scale)
     O.flag_show_minimum_covering_sphere = False
     O.flag_show_rotation_center = False
     _ = app.co.labels_threshold
     O.flag_show_labels = (_ == 0 or len(O.points) <= _)
     O.labels_display_list = None
     O.lines_display_list = None
     O.points_display_list = None
def run(args):
    assert len(args) == 0
    from cctbx.crystal.distance_based_connectivity import \
      build_simple_two_way_bond_sets
    from scitbx.array_family import flex
    sites_cart = flex.vec3_double([(25.655, 43.266, 42.630),
                                   (24.038, 43.853, 43.337),
                                   (23.048, 44.525, 43.290),
                                   (21.223, 44.207, 41.475),
                                   (24.951, 47.170, 37.585),
                                   (19.298, 46.942, 51.808)])
    elements = flex.std_string(["S", "C", "N", "CU", "ZN", "CA"])
    bond_list = build_simple_two_way_bond_sets(sites_cart=sites_cart,
                                               elements=elements)
    assert [sorted(b) for b in bond_list] == [[1], [0, 2], [1, 3], [2], [], []]
    #
    # caffeine
    sites_cart = flex.vec3_double([
        (-2.986, 0.015, 1.643), (-1.545, 0.015, 1.643), (-0.733, 0.015, 2.801),
        (0.592, 0.015, 2.395), (0.618, 0.015, 1.034), (1.758, 0.015, 0.102),
        (3.092, -0.06, 0.694), (1.525, 0.015, -1.360), (2.489, -0.024, -2.139),
        (0.158, 0.015, -1.888), (-0.025, 0.024, -3.330),
        (-0.986, 0.015, -0.959), (-2.155, 0.008, -1.408),
        (-0.733, 0.015, 0.565), (-3.346, 0.016, 2.662), (-3.347, 0.896, 1.133),
        (-3.347, -0.868, 1.136), (-1.083, 0.02, 3.822), (3.184, -0.975, 1.26),
        (3.245, 0.785, 1.348), (3.835, -0.047, -0.09), (0.508, 0.861, -3.756),
        (-1.076, 0.113, -3.560), (0.358, -0.896, -3.748)
    ])
    elements = flex.std_string([
        ' C', ' N', ' C', ' N', ' C', ' N', ' C', ' C', ' O', ' N', ' C', ' C',
        ' O', ' C', ' H', ' H', ' H', ' H', ' H', ' H', ' H', ' H', ' H', ' H'
    ])
    bonds = build_simple_two_way_bond_sets(sites_cart=sites_cart,
                                           elements=elements)
    assert bonds.size() == sites_cart.size()
    assert list(bonds[0]) == [1, 14, 15, 16]
    #
    print "OK"
Ejemplo n.º 5
0
 def set_points_and_lines(
       O,
       app,
       minimum_covering_sphere_view_scale=1.3):
   pdb_atoms = app.pdb_atoms
   pdb_atoms.set_chemical_element_simple_if_necessary()
   atom_tmp_sentinel = pdb_atoms.reset_tmp(first_value=0, increment=0)
   for i,rg in enumerate(app.pdb_hierarchy.residue_groups()):
     for atom in rg.atoms():
       atom.tmp = i
   O.points = pdb_atoms.extract_xyz()
   if (app.co.serial_labels):
     m = ""
     need_m = (app.pdb_hierarchy.models_size() != 1)
     for mdl in app.pdb_hierarchy.models():
       if (need_m): m = mdl.id.strip() + ":"
       for i in xrange(mdl.atoms_size()):
         O.labels.append(m+str(i))
     assert len(O.labels) == O.points.size()
   else:
     rg_done = set()
     for atom in pdb_atoms:
       i = atom.tmp
       if (i not in rg_done):
         rg_done.add(i)
         l = atom.id_str()
       else:
         l = atom.name
       O.labels.append(l)
   from cctbx.crystal.distance_based_connectivity import \
     build_simple_two_way_bond_sets
   bond_sets = build_simple_two_way_bond_sets(
     sites_cart=O.points,
     elements=pdb_atoms.extract_element())
   for i,bond_set in enumerate(bond_sets):
     for j in bond_set:
       if (i < j):
         line = (i,j)
         ai, aj = [pdb_atoms[_] for _ in line]
         if (ai.is_in_same_conformer_as(aj)):
           O.line_i_seqs.append(line)
           if (ai.tmp == aj.tmp):
             if (ai.tmp % 2 == 0):
               color = (0,0,1)
             else:
               color = (0,1,0)
           else:
             color = (1,0,0)
           O.line_colors[line] = color
   del atom_tmp_sentinel
   from scitbx.math import minimum_covering_sphere, sphere_3d
   mcs = minimum_covering_sphere(O.points, epsilon=1.e-2)
   O.minimum_covering_sphere = sphere_3d(
     center=mcs.center(),
     radius=mcs.radius()*minimum_covering_sphere_view_scale)
   O.flag_show_minimum_covering_sphere = False
   O.flag_show_rotation_center = False
   _ = app.co.labels_threshold
   O.flag_show_labels = (_ == 0 or len(O.points) <= _)
   O.labels_display_list = None
   O.lines_display_list = None
   O.points_display_list = None