コード例 #1
0
def exercise_planarity():
  p = geometry_restraints.motif_planarity()
  assert p.atom_names.size() == 0
  assert p.weights.size() == 0
  assert p.id == ""
  p = geometry_restraints.motif_planarity(
    atom_names=flex.std_string(["a", "b"]),
    weights=flex.double([1.5, 2.5]),
    id="t")
  assert list(p.atom_names) == ["a", "b"]
  assert list(p.weights) == [1.5, 2.5]
  assert p.id == "t"
  p.atom_names = flex.std_string(["x", "y", "z"])
  assert list(p.atom_names) == ["x", "y", "z"]
  p.weights = flex.double([3.5, 6.5])
  assert list(p.weights) == [3.5, 6.5]
  p.id = "u"
  assert p.id == "u"
コード例 #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
 assert list(a.motif_ids) == ["-", "+"]
 a.atom = geometry_restraints.motif_atom(name="a")
 assert a.atom.name == "a"
 a.motif_atom_name = "x"
 assert a.motif_atom_name == "x"
 a.bond = geometry_restraints.motif_bond(atom_names=["b", "c"])
 assert a.bond.atom_names == ("b", "c")
 a.angle = geometry_restraints.motif_angle(atom_names=["d", "e", "f"])
 assert a.angle.atom_names == ("d", "e", "f")
 a.dihedral = geometry_restraints.motif_dihedral(atom_names=["h","i","j","k"])
 assert a.dihedral.atom_names == ("h", "i", "j", "k")
 a.chirality = geometry_restraints.motif_chirality(
   atom_names=["l","m","n","o"])
 assert a.chirality.atom_names == ("l", "m", "n", "o")
 a.planarity = geometry_restraints.motif_planarity(
   atom_names=flex.std_string(["p", "q"]),
   weights=flex.double([1,2]))
 a.planarity_motif_id = "h"
 assert a.planarity_motif_id == "h"
 a.set_planarity_atom_actions(["add", "change", "delete"])
 assert a.planarity_atom_actions_as_list() == ["add", "change", "delete"]
 try: a.set_planarity_atom_actions(["add", "chnage", "delete"])
 except RuntimeError, e:
   assert str(e) == 'Unknown cctbx::geometry_restraints::motif::alteration' \
     '::action_type: "chnage"\n' \
     '  Possible action types are: "", "add", "delete", "change"'
 else: raise Exception_expected
 assert a.planarity_atom_actions_as_list() == []
 assert list(a.planarity.atom_names) == ["p", "q"]
 assert a.set_change_partial_charge(state=True) is a
 assert a.change_partial_charge()
コード例 #4
0
ファイル: cif_types.py プロジェクト: cctbx/cctbx-playground
 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
コード例 #5
0
ファイル: cif_types.py プロジェクト: zhuligs/cctbx_project
 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
コード例 #6
0
ファイル: tst_motif.py プロジェクト: yayahjb/cctbx_project
def exercise_alteration():
    a = geometry_restraints.motif_alteration()
    assert a.action == ""
    assert a.operand == ""
    a = geometry_restraints.motif_alteration(action="add")
    assert a.action == "add"
    assert a.operand == ""
    a = geometry_restraints.motif_alteration(action="change", operand="bond")
    assert a.action == "change"
    assert a.operand == "bond"
    assert a.motif_ids.size() == 0
    assert a.atom.name == ""
    assert a.motif_atom_name == ""
    assert a.bond.atom_names == ("", "")
    assert a.angle.atom_names == ("", "", "")
    assert a.dihedral.atom_names == ("", "", "", "")
    assert a.chirality.atom_names == ("", "", "", "")
    assert a.planarity.atom_names.size() == 0
    assert a.planarity_motif_id == ""
    assert a.planarity_atom_actions_as_list() == []
    assert not a.change_partial_charge()
    assert not a.change_distance_ideal()
    assert not a.change_weight()
    assert not a.change_angle_ideal()
    assert not a.change_periodicity()
    assert not a.change_both_signs()
    assert not a.change_volume_ideal()
    for action in ["", "add", "delete", "change"]:
        a.action = action
        assert a.action == action
    try:
        a.action = "chnage"
    except RuntimeError as e:
        assert str(e) == 'Unknown cctbx::geometry_restraints::motif::alteration' \
          '::action_type: "chnage"\n' \
          '  Possible action types are: "", "add", "delete", "change"'
    else:
        raise Exception_expected
    for operand in [
            "", "atom", "bond", "angle", "dihedral", "chirality", "planarity"
    ]:
        a.operand = operand
        assert a.operand == operand
    try:
        a.operand = "diehdral"
    except RuntimeError as e:
        assert str(e) == 'Unknown cctbx::geometry_restraints::motif::alteration' \
          '::operand_type: "diehdral"\n' \
          '  Possible operand types are: "", "atom", "bond", "angle",' \
          ' "dihedral", "chirality", "planarity"'
    else:
        raise Exception_expected
    a.motif_ids = flex.std_string(["-", "+"])
    assert list(a.motif_ids) == ["-", "+"]
    a.atom = geometry_restraints.motif_atom(name="a")
    assert a.atom.name == "a"
    a.motif_atom_name = "x"
    assert a.motif_atom_name == "x"
    a.bond = geometry_restraints.motif_bond(atom_names=["b", "c"])
    assert a.bond.atom_names == ("b", "c")
    a.angle = geometry_restraints.motif_angle(atom_names=["d", "e", "f"])
    assert a.angle.atom_names == ("d", "e", "f")
    a.dihedral = geometry_restraints.motif_dihedral(
        atom_names=["h", "i", "j", "k"])
    assert a.dihedral.atom_names == ("h", "i", "j", "k")
    a.chirality = geometry_restraints.motif_chirality(
        atom_names=["l", "m", "n", "o"])
    assert a.chirality.atom_names == ("l", "m", "n", "o")
    a.planarity = geometry_restraints.motif_planarity(
        atom_names=flex.std_string(["p", "q"]), weights=flex.double([1, 2]))
    a.planarity_motif_id = "h"
    assert a.planarity_motif_id == "h"
    a.set_planarity_atom_actions(["add", "change", "delete"])
    assert a.planarity_atom_actions_as_list() == ["add", "change", "delete"]
    try:
        a.set_planarity_atom_actions(["add", "chnage", "delete"])
    except RuntimeError as e:
        assert str(e) == 'Unknown cctbx::geometry_restraints::motif::alteration' \
          '::action_type: "chnage"\n' \
          '  Possible action types are: "", "add", "delete", "change"'
    else:
        raise Exception_expected
    assert a.planarity_atom_actions_as_list() == []
    assert list(a.planarity.atom_names) == ["p", "q"]
    assert a.set_change_partial_charge(state=True) is a
    assert a.change_partial_charge()
    assert not a.change_distance_ideal()
    assert a.set_change_distance_ideal(state=True) is a
    assert a.change_distance_ideal()
    assert not a.change_weight()
    assert a.set_change_weight(state=True) is a
    assert a.change_weight()
    assert not a.change_angle_ideal()
    assert a.set_change_angle_ideal(state=True) is a
    assert a.change_angle_ideal()
    assert not a.change_periodicity()
    assert a.set_change_periodicity(state=True) is a
    assert a.change_periodicity()
    assert not a.change_both_signs()
    assert a.set_change_both_signs(state=True) is a
    assert a.change_both_signs()
    assert not a.change_volume_ideal()
    assert a.set_change_volume_ideal(state=True) is a
    assert a.change_volume_ideal()