示例#1
0
 def as_geometry_restraints_motif(self):
   result = geometry_restraints.motif()
   result.id = if_none(self.chem_comp.id, "")
   result.description = if_none(self.chem_comp.name, "").strip()
   if (self.source_info is not None):
     result.info.append(self.source_info)
   result.set_atoms([
     geometry_restraints.motif_atom(
       name=if_none(atom.atom_id, ""),
       scattering_type=if_none(atom.type_symbol, ""),
       nonbonded_type=if_none(atom.type_energy, ""),
       partial_charge=if_none(atom.partial_charge, 0))
         for atom in self.atom_list])
   result.set_bonds([
     geometry_restraints.motif_bond(
       atom_names=[
         if_none(bond.atom_id_1, ""),
         if_none(bond.atom_id_2, "")],
       type=if_none(bond.type, ""),
       distance_ideal=if_none(bond.value_dist, 0),
       weight=esd_as_weight(bond.value_dist_esd))
         for bond in self.bond_list])
   result.set_angles([
     geometry_restraints.motif_angle(
       atom_names=[
         if_none(angle.atom_id_1, ""),
         if_none(angle.atom_id_2, ""),
         if_none(angle.atom_id_3, "")],
       angle_ideal=if_none(angle.value_angle, 0),
       weight=esd_as_weight(angle.value_angle_esd))
         for angle in self.angle_list])
   result.set_dihedrals([
     geometry_restraints.motif_dihedral(
       atom_names=[
         if_none(tor.atom_id_1, ""),
         if_none(tor.atom_id_2, ""),
         if_none(tor.atom_id_3, ""),
         if_none(tor.atom_id_4, "")],
       angle_ideal=if_none(tor.value_angle, 0),
       weight=esd_as_weight(tor.value_angle_esd),
       periodicity=if_none(tor.period, 0),
       id=tor.id)
         for tor in self.tor_list])
   result.set_chiralities([
     geometry_restraints.motif_chirality(
       atom_names=[
         if_none(chir.atom_id_centre, ""),
         if_none(chir.atom_id_1, ""),
         if_none(chir.atom_id_2, ""),
         if_none(chir.atom_id_3, "")],
       volume_sign=chir.volume_sign,
       id=chir.id)
         for chir in self.chir_list])
   planarities = []
   for plane in self.get_planes():
     atom_names = flex.std_string([if_none(plane_atom.atom_id, "")
       for plane_atom in plane.plane_atoms])
     weights = flex.double([esd_as_weight(plane_atom.dist_esd)
       for plane_atom in plane.plane_atoms])
     planarities.append(
       geometry_restraints.motif_planarity(
         atom_names=atom_names,
         weights=weights,
         id=plane.plane_id))
   result.set_planarities(planarities)
   return result
示例#2
0
def exercise_motif():
  m = geometry_restraints.motif()
  assert m.id == ""
  assert m.description == ""
  assert m.info.size() == 0
  assert m.manipulation_ids.size() == 0
  assert len(m.atoms_as_list()) == 0
  assert len(m.bonds_as_list()) == 0
  assert len(m.angles_as_list()) == 0
  assert len(m.dihedrals_as_list()) == 0
  assert len(m.chiralities_as_list()) == 0
  assert len(m.planarities_as_list()) == 0
  m.id = "a"
  assert m.id == "a"
  m.description = "b"
  assert m.description == "b"
  m.info.append("c")
  m.info.append("d")
  assert m.info.size() == 2
  m.manipulation_ids.append("e")
  m.manipulation_ids.append("f")
  assert m.manipulation_ids.size() == 2
  l = [geometry_restraints.motif_atom(*a, **k) for a,k in [
    ((), {"name": "a", "scattering_type": "b", "nonbonded_type": "c",
     "partial_charge": -0.1}),
    (("d"),{})]]
  m.set_atoms(l)
  assert [atom.name for atom in m.atoms_as_list()] == ["a", "d"]
  l = [geometry_restraints.motif_bond(*a, **k) for a,k in [
    ((), {"atom_names": ("a", "b"), "type": "c", "distance_ideal": 2.3,
     "weight": 11.5, "id": "d"}),
    ((("e", "f"),),{})]]
  m.set_bonds(l)
  assert [bond.atom_names for bond in m.bonds_as_list()] \
      == [("a", "b"), ("e", "f")]
  l = [geometry_restraints.motif_angle(*a, **k) for a,k in [
    ((), {"atom_names": ("a", "b", "c"), "angle_ideal": 3.2,
     "weight": 15.1, "id": "d"}),
    ((("e", "f", "g"),),{})]]
  m.set_angles(l)
  assert [angle.atom_names for angle in m.angles_as_list()] \
      == [("a", "b", "c"), ("e", "f", "g")]
  l = [geometry_restraints.motif_dihedral(*a, **k) for a,k in [
    ((), {"atom_names": ("a", "b", "c", "d"), "angle_ideal": 4.3,
     "weight": 1.5, "periodicity": 3, "id": "e"}),
    ((("f", "g", "h", "i"),),{})]]
  m.set_dihedrals(l)
  assert [dihedral.atom_names for dihedral in m.dihedrals_as_list()] \
      == [("a", "b", "c", "d"), ("f", "g", "h", "i")]
  l = [geometry_restraints.motif_chirality(*a, **k) for a,k in [
    ((), {"atom_names": ("a", "b", "c", "d"), "volume_sign": "e",
     "both_signs": True, "volume_ideal": 10.3, "weight": 1.5, "id": "f"}),
    ((("g", "h", "i", "j"),),{})]]
  m.set_chiralities(l)
  assert [chirality.atom_names for chirality in m.chiralities_as_list()] \
      == [("a", "b", "c", "d"), ("g", "h", "i", "j")]
  l = [geometry_restraints.motif_planarity(
         atom_names=flex.std_string(["a", "b"]),
         weights=flex.double([1,2]),
         id="c"),
       geometry_restraints.motif_planarity(
         atom_names=flex.std_string(["d"]),
         weights=flex.double([3]))]
  m.set_planarities(l)
  assert [list(planarity.atom_names)
            for planarity in m.planarities_as_list()] \
      == [["a", "b"], ["d"]]
  out = StringIO()
  m.show(out=out, prefix="&*")
  assert not show_diff(out.getvalue(), """\
&*geometry_restraints.motif {
&*  id = "a"
&*  description = "b"
&*  info = "c"
&*  info = "d"
&*  manipulation_id = "e"
&*  manipulation_id = "f"
&*  atom = [name scattering_type nonbonded_type partial_charge]
&*  atom = "a" "b" "c" -0.1
&*  atom = "d" "" "" 0
&*  bond = [atom_name*2 type distance_ideal weight id]
&*  bond = "a" "b" "c" 2.3 11.5 "d"
&*  bond = "e" "f" "" 0 0 ""
&*  angle = [atom_name*3 angle_ideal weight id]
&*  angle = "a" "b" "c" 3.2 15.1 "d"
&*  angle = "e" "f" "g" 0 0 ""
&*  dihedral = [atom_name*4 angle_ideal weight periodicity id]
&*  dihedral = "a" "b" "c" "d" 4.3 1.5 3 "e"
&*  dihedral = "f" "g" "h" "i" 0 0 0 ""
&*  chirality = [atom_name*4 volume_sign both_signs volume_ideal weight id]
&*  chirality = "a" "b" "c" "d" "e" True 10.3 1.5 "f"
&*  chirality = "g" "h" "i" "j" "" False 0 0 ""
&*  planarity {
&*    id = "c"
&*    atom = [name weight]
&*    atom = "a" 1
&*    atom = "b" 2
&*  }
&*  planarity {
&*    id = ""
&*    atom = [name weight]
&*    atom = "d" 3
&*  }
&*}
""")
  out = StringIO()
  m.show(out=out)
  phil.parse(input_string=out.getvalue())
示例#3
0
 def as_geometry_restraints_motif(self):
     result = geometry_restraints.motif()
     result.id = if_none(self.chem_comp.id, "")
     result.description = if_none(self.chem_comp.name, "").strip()
     if (self.source_info is not None):
         result.info.append(self.source_info)
     result.set_atoms([
         geometry_restraints.motif_atom(
             name=if_none(atom.atom_id, ""),
             scattering_type=if_none(atom.type_symbol, ""),
             nonbonded_type=if_none(atom.type_energy, ""),
             partial_charge=if_none(atom.partial_charge, 0))
         for atom in self.atom_list
     ])
     result.set_bonds([
         geometry_restraints.motif_bond(
             atom_names=[
                 if_none(bond.atom_id_1, ""),
                 if_none(bond.atom_id_2, "")
             ],
             type=if_none(bond.type, ""),
             distance_ideal=if_none(bond.value_dist, 0),
             weight=esd_as_weight(bond.value_dist_esd))
         for bond in self.bond_list
     ])
     result.set_angles([
         geometry_restraints.motif_angle(
             atom_names=[
                 if_none(angle.atom_id_1, ""),
                 if_none(angle.atom_id_2, ""),
                 if_none(angle.atom_id_3, "")
             ],
             angle_ideal=if_none(angle.value_angle, 0),
             weight=esd_as_weight(angle.value_angle_esd))
         for angle in self.angle_list
     ])
     result.set_dihedrals([
         geometry_restraints.motif_dihedral(
             atom_names=[
                 if_none(tor.atom_id_1, ""),
                 if_none(tor.atom_id_2, ""),
                 if_none(tor.atom_id_3, ""),
                 if_none(tor.atom_id_4, "")
             ],
             angle_ideal=if_none(tor.value_angle, 0),
             weight=esd_as_weight(tor.value_angle_esd),
             periodicity=if_none(tor.period, 0),
             id=tor.id) for tor in self.tor_list
     ])
     result.set_chiralities([
         geometry_restraints.motif_chirality(atom_names=[
             if_none(chir.atom_id_centre, ""),
             if_none(chir.atom_id_1, ""),
             if_none(chir.atom_id_2, ""),
             if_none(chir.atom_id_3, "")
         ],
                                             volume_sign=chir.volume_sign,
                                             id=chir.id)
         for chir in self.chir_list
     ])
     planarities = []
     for plane in self.get_planes():
         atom_names = flex.std_string([
             if_none(plane_atom.atom_id, "")
             for plane_atom in plane.plane_atoms
         ])
         weights = flex.double([
             esd_as_weight(plane_atom.dist_esd)
             for plane_atom in plane.plane_atoms
         ])
         planarities.append(
             geometry_restraints.motif_planarity(atom_names=atom_names,
                                                 weights=weights,
                                                 id=plane.plane_id))
     result.set_planarities(planarities)
     return result