Exemplo n.º 1
0
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, e:
    assert str(e) == 'Unknown cctbx::geometry_restraints::motif::alteration' \
      '::action_type: "chnage"\n' \
      '  Possible action types are: "", "add", "delete", "change"'
Exemplo n.º 2
0
def exercise_manipulation():
  m = geometry_restraints.motif_manipulation()
  assert m.id == ""
  assert m.description == ""
  assert m.info.size() == 0
  assert len(m.alterations_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 list(m.info) == ["c", "d"]
  alts = []
  a = geometry_restraints.motif_alteration()
  a.action = "add"
  a.operand = "bond"
  alts.append(a)
  a = geometry_restraints.motif_alteration()
  a.action = "delete"
  a.operand = "angle"
  alts.append(a)
  m.set_alterations(alts)
  l = m.alterations_as_list()
  assert len(l) == 2
  assert l[0].action == "add"
  assert l[0].operand == "bond"
  assert l[1].action == "delete"
  assert l[1].operand == "angle"
  #
  m = geometry_restraints.motif_manipulation()
  m.id = "a"
  m.description = "b"
  m.info.append("c")
  #
  alterations = []
  a = geometry_restraints.motif_alteration(action="add", operand="atom")
  a.motif_ids.append("1")
  a.atom.name = "x"
  a.atom.scattering_type = "y"
  a.atom.nonbonded_type = "z"
  a.atom.partial_charge = -0.2
  alterations.append(a)
  for change_partial_charge in [False, True]:
    a = geometry_restraints.motif_alteration(action="change", operand="atom")
    a.motif_ids.append("0")
    a.motif_atom_name = "p"
    a.atom.name = "q"
    a.atom.scattering_type = "r"
    a.atom.nonbonded_type = "s"
    a.atom.partial_charge = 0.3
    a.set_change_partial_charge(state=change_partial_charge)
    alterations.append(a)
  a = geometry_restraints.motif_alteration(action="delete", operand="atom")
  a.motif_ids.append("3")
  a.motif_atom_name = "d"
  alterations.append(a)
  #
  a = geometry_restraints.motif_alteration(action="add", operand="bond")
  a.motif_ids.append("1")
  a.motif_ids.append("2")
  a.bond.atom_names = ["j", "k"]
  a.bond.distance_ideal = 1.2
  a.bond.weight = 3.1
  a.bond.id = "s"
  alterations.append(a)
  for change_distance_ideal in [False, True]:
    for change_weight in [False, True]:
      a = geometry_restraints.motif_alteration(action="change", operand="bond")
      a.motif_ids.append("3")
      a.motif_ids.append("4")
      a.bond.atom_names = ["l", "m"]
      a.bond.distance_ideal = 4.5
      a.bond.weight = 2.8
      a.bond.id = "g"
      a.set_change_distance_ideal(state=change_distance_ideal)
      a.set_change_weight(state=change_weight)
      alterations.append(a)
  a = geometry_restraints.motif_alteration(action="delete", operand="bond")
  a.motif_ids.append("5")
  a.motif_ids.append("6")
  a.bond.atom_names = ["t", "n"]
  alterations.append(a)
  #
  a = geometry_restraints.motif_alteration(action="add", operand="angle")
  a.motif_ids.append("1")
  a.motif_ids.append("2")
  a.motif_ids.append("3")
  a.angle.atom_names = ["j", "k", "l"]
  a.angle.angle_ideal = 1.2
  a.angle.weight = 3.1
  a.angle.id = "s"
  alterations.append(a)
  for change_angle_ideal in [False, True]:
    for change_weight in [False, True]:
      a = geometry_restraints.motif_alteration(
        action="change", operand="angle")
      a.motif_ids.append("3")
      a.motif_ids.append("4")
      a.motif_ids.append("5")
      a.angle.atom_names = ["l", "m", "g"]
      a.angle.angle_ideal = 4.5
      a.angle.weight = 2.8
      a.angle.id = "g"
      a.set_change_angle_ideal(state=change_angle_ideal)
      a.set_change_weight(state=change_weight)
      alterations.append(a)
  a = geometry_restraints.motif_alteration(action="delete", operand="angle")
  a.motif_ids.append("6")
  a.motif_ids.append("7")
  a.motif_ids.append("8")
  a.angle.atom_names = ["t", "n", "d"]
  alterations.append(a)
  #
  a = geometry_restraints.motif_alteration(action="add", operand="dihedral")
  a.motif_ids.append("1")
  a.motif_ids.append("2")
  a.motif_ids.append("3")
  a.motif_ids.append("4")
  a.dihedral.atom_names = ["j", "k", "l", "r"]
  a.dihedral.angle_ideal = 1.2
  a.dihedral.weight = 3.1
  a.dihedral.periodicity = 20
  a.dihedral.id = "s"
  alterations.append(a)
  for change_angle_ideal in [False, True]:
    for change_weight in [False, True]:
      for change_periodicity in [False, True]:
        a = geometry_restraints.motif_alteration(
          action="change", operand="dihedral")
        a.motif_ids.append("5")
        a.motif_ids.append("6")
        a.motif_ids.append("7")
        a.motif_ids.append("8")
        a.dihedral.atom_names = ["l", "m", "g", "e"]
        a.dihedral.angle_ideal = 4.5
        a.dihedral.weight = 2.8
        a.dihedral.periodicity = 13
        a.dihedral.id = "g"
        a.set_change_angle_ideal(state=change_angle_ideal)
        a.set_change_weight(state=change_weight)
        a.set_change_periodicity(state=change_periodicity)
        alterations.append(a)
  a = geometry_restraints.motif_alteration(action="delete", operand="dihedral")
  a.motif_ids.append("9")
  a.motif_ids.append("10")
  a.motif_ids.append("11")
  a.motif_ids.append("12")
  a.dihedral.atom_names = ["t", "n", "d", "y"]
  alterations.append(a)
  #
  a = geometry_restraints.motif_alteration(action="add", operand="chirality")
  a.motif_ids.append("1")
  a.motif_ids.append("2")
  a.motif_ids.append("3")
  a.motif_ids.append("4")
  a.chirality.atom_names = ["j", "k", "l", "r"]
  a.chirality.volume_sign = "x"
  a.chirality.volume_ideal = 1.2
  a.chirality.weight = 3.1
  a.chirality.id = "w"
  alterations.append(a)
  for change_volume_ideal in [False, True]:
    for change_weight in [False, True]:
      a = geometry_restraints.motif_alteration(
        action="change", operand="chirality")
      a.motif_ids.append("5")
      a.motif_ids.append("6")
      a.motif_ids.append("7")
      a.motif_ids.append("8")
      a.chirality.atom_names = ["l", "m", "g", "e"]
      a.chirality.volume_sign = "u"
      a.chirality.volume_ideal = 4.5
      a.chirality.weight = 2.8
      a.chirality.id = "g"
      a.set_change_volume_ideal(state=change_volume_ideal)
      a.set_change_weight(state=change_weight)
      alterations.append(a)
  a = geometry_restraints.motif_alteration(
    action="delete", operand="chirality")
  a.motif_ids.append("9")
  a.motif_ids.append("10")
  a.motif_ids.append("11")
  a.motif_ids.append("12")
  a.chirality.atom_names = ["t", "n", "d", "y"]
  alterations.append(a)
  #
  a = geometry_restraints.motif_alteration(action="add", operand="planarity")
  a.planarity_motif_id = "7"
  a.planarity.id = "e"
  a.motif_ids.append("1")
  a.motif_ids.append("2")
  a.motif_ids.append("3")
  a.planarity.atom_names.append("s")
  a.planarity.atom_names.append("d")
  a.planarity.atom_names.append("f")
  a.planarity.weights.append(1.2)
  a.planarity.weights.append(2.3)
  a.planarity.weights.append(3.4)
  alterations.append(a)
  a = geometry_restraints.motif_alteration(
    action="change", operand="planarity")
  a.planarity_motif_id = "8"
  a.planarity.id = "f"
  a.set_planarity_atom_actions(["add", "change", "delete"])
  a.motif_ids.append("1")
  a.motif_ids.append("2")
  a.motif_ids.append("3")
  a.planarity.atom_names.append("s")
  a.planarity.atom_names.append("d")
  a.planarity.atom_names.append("f")
  a.planarity.weights.append(1.2)
  a.planarity.weights.append(2.3)
  a.planarity.weights.append(0)
  alterations.append(a)
  a = geometry_restraints.motif_alteration(
    action="delete", operand="planarity")
  a.planarity_motif_id = "4"
  a.planarity.id = "n"
  alterations.append(a)
  #
  m.set_alterations(alterations)
  out = StringIO()
  m.show(out=out, prefix="^")
  assert not show_diff(out.getvalue(), """\
^geometry_restraints.motif_manipulation {
^  id = "a"
^  description = "b"
^  info = "c"
^  atom = add [motif_id name scattering_type nonbonded_type partial_charge]
^  atom = add "1" "x" "y" "z" -0.2
^  atom = change [motif_id motif_atom_name \\
^                 name scattering_type nonbonded_type partial_charge]
^  atom = change "0" "p" \\
^                "q" "r" "s" None
^  atom = change "0" "p" \\
^                "q" "r" "s" 0.3
^  atom = delete [motif_id motif_atom_name]
^  atom = delete "3" "d"
^  bond = add [(motif_id atom_name)*2 type distance_ideal weight id]
^  bond = add "1" "j" "2" "k" 1.2 3.1 "s"
^  bond = change [(motif_id atom_name)*2 type distance_ideal weight id]
^  bond = change "3" "l" "4" "m" None None "g"
^  bond = change "3" "l" "4" "m" None 2.8 "g"
^  bond = change "3" "l" "4" "m" 4.5 None "g"
^  bond = change "3" "l" "4" "m" 4.5 2.8 "g"
^  bond = delete [(motif_id atom_name)*2]
^  bond = delete "5" "t" "6" "n"
^  angle = add [(motif_id atom_name)*3 type angle_ideal weight id]
^  angle = add "1" "j" "2" "k" "3" "l" 1.2 3.1 "s"
^  angle = change [(motif_id atom_name)*3 type angle_ideal weight id]
^  angle = change "3" "l" "4" "m" "5" "g" None None "g"
^  angle = change "3" "l" "4" "m" "5" "g" None 2.8 "g"
^  angle = change "3" "l" "4" "m" "5" "g" 4.5 None "g"
^  angle = change "3" "l" "4" "m" "5" "g" 4.5 2.8 "g"
^  angle = delete [(motif_id atom_name)*3]
^  angle = delete "6" "t" "7" "n" "8" "d"
^  dihedral = add [(motif_id atom_name)*4 angle_ideal weight periodicity id]
^  dihedral = add "1" "j" "2" "k" "3" "l" "4" "r" 1.2 3.1 20 "s"
^  dihedral = change [(motif_id atom_name)*4 angle_ideal weight periodicity id]
^  dihedral = change "5" "l" "6" "m" "7" "g" "8" "e" None None None "g"
^  dihedral = change "5" "l" "6" "m" "7" "g" "8" "e" None None 13 "g"
^  dihedral = change "5" "l" "6" "m" "7" "g" "8" "e" None 2.8 None "g"
^  dihedral = change "5" "l" "6" "m" "7" "g" "8" "e" None 2.8 13 "g"
^  dihedral = change "5" "l" "6" "m" "7" "g" "8" "e" 4.5 None None "g"
^  dihedral = change "5" "l" "6" "m" "7" "g" "8" "e" 4.5 None 13 "g"
^  dihedral = change "5" "l" "6" "m" "7" "g" "8" "e" 4.5 2.8 None "g"
^  dihedral = change "5" "l" "6" "m" "7" "g" "8" "e" 4.5 2.8 13 "g"
^  dihedral = delete [(motif_id atom_name)*4]
^  dihedral = delete "9" "t" "10" "n" "11" "d" "12" "y"
^  chirality = add [(motif_id atom_name)*4 \\
^                   volume_sign volume_ideal weight id]
^  chirality = add "1" "j" "2" "k" "3" "l" "4" "r" \\
^                  "x" 1.2 3.1 "w"
^  chirality = change [(motif_id atom_name)*4 \\
^                      volume_sign volume_ideal weight id]
^  chirality = change "5" "l" "6" "m" "7" "g" "8" "e" \\
^                     "u" None None "g"
^  chirality = change "5" "l" "6" "m" "7" "g" "8" "e" \\
^                     "u" None 2.8 "g"
^  chirality = change "5" "l" "6" "m" "7" "g" "8" "e" \\
^                     "u" 4.5 None "g"
^  chirality = change "5" "l" "6" "m" "7" "g" "8" "e" \\
^                     "u" 4.5 2.8 "g"
^  chirality = delete [(motif_id atom_name)*4]
^  chirality = delete "9" "t" "10" "n" "11" "d" "12" "y"
^  planarity {
^    action = add
^    motif_id = "7"
^    id = "e"
^    atom = [motif_id name weight]
^    atom = "1" "s" 1.2
^    atom = "2" "d" 2.3
^    atom = "3" "f" 3.4
^  }
^  planarity {
^    action = change
^    motif_id = "8"
^    id = "f"
^    atom = add [motif_id name weight]
^    atom = add "1" "s" 1.2
^    atom = change [motif_id name weight]
^    atom = change "2" "d" 2.3
^    atom = delete [motif_id name]
^    atom = delete "3" "f"
^  }
^  planarity {
^    action = delete
^    motif_id = "4"
^    id = "n"
^  }
^}
""")
  out = StringIO()
  m.show(out=out)
  phil.parse(input_string=out.getvalue())
Exemplo n.º 3
0
 def as_geometry_restraints_motif_manipulation(self):
   result = geometry_restraints.motif_manipulation()
   result.id = if_none(self.chem_mod.id, "")
   result.description = if_none(self.chem_mod.name, "")
   if (self.source_info is not None):
     result.info.append(self.source_info)
   alts = []
   for atom in self.atom_list:
     a = geometry_restraints.motif_alteration(
       action=if_none(atom.function, ""), operand="atom")
     a.motif_ids.append("")
     if (a.action != "add"):
       a.motif_atom_name = if_none(atom.atom_id, "")
     a.atom.name = if_none(atom.new_atom_id, "")
     a.atom.scattering_type = if_none(atom.new_type_symbol, "")
     a.atom.nonbonded_type = if_none(atom.new_type_energy, "")
     a.atom.partial_charge = if_none(atom.new_partial_charge, 0)
     if (a.action == "change"):
       a.set_change_partial_charge(state=atom.new_partial_charge is not None)
     alts.append(a)
   for bond in self.bond_list:
     a = geometry_restraints.motif_alteration(
       action=if_none(bond.function, ""), operand="bond")
     a.motif_ids.append("")
     a.motif_ids.append("")
     a.bond.atom_names = [
       if_none(bond.atom_id_1, ""),
       if_none(bond.atom_id_2, "")]
     a.bond.type = if_none(bond.new_type, "")
     a.bond.distance_ideal = if_none(bond.new_value_dist, 0)
     a.bond.weight = esd_as_weight(bond.new_value_dist_esd)
     if (a.action == "change"):
       a.set_change_distance_ideal(state=bond.new_value_dist is not None)
       a.set_change_weight(state=bond.new_value_dist_esd is not None)
     alts.append(a)
   for angle in self.angle_list:
     a = geometry_restraints.motif_alteration(
       action=if_none(bond.function, ""), operand="angle")
     a.motif_ids.append("")
     a.motif_ids.append("")
     a.motif_ids.append("")
     a.angle.atom_names = [
       if_none(angle.atom_id_1, ""),
       if_none(angle.atom_id_2, ""),
       if_none(angle.atom_id_3, "")]
     a.angle.angle_ideal = if_none(angle.new_value_angle, 0)
     a.angle.weight = esd_as_weight(angle.new_value_angle_esd)
     if (a.action == "change"):
       a.set_change_angle_ideal(state=angle.new_value_angle is not None)
       a.set_change_weight(state=angle.new_value_angle_esd is not None)
     alts.append(a)
   for tor in self.tor_list:
     a = geometry_restraints.motif_alteration(
       action=if_none(tor.function, ""), operand="dihedral")
     a.motif_ids.append("")
     a.motif_ids.append("")
     a.motif_ids.append("")
     a.motif_ids.append("")
     a.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, "")]
     a.dihedral.angle_ideal = if_none(tor.new_value_angle, 0)
     a.dihedral.weight = esd_as_weight(tor.new_value_angle_esd)
     a.dihedral.periodicity = if_none(tor.new_period, 0)
     a.dihedral.id = if_none(tor.id, "")
     if (a.action == "change"):
       a.set_change_angle_ideal(state=tor.new_value_angle is not None)
       a.set_change_weight(state=tor.new_value_angle_esd is not None)
       a.set_change_periodicity(state=tor.new_period is not None)
     alts.append(a)
   for chir in self.chir_list:
     a = geometry_restraints.motif_alteration(
       action=if_none(chir.function, ""), operand="chirality")
     a.motif_ids.append("")
     a.motif_ids.append("")
     a.motif_ids.append("")
     a.motif_ids.append("")
     a.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, "")]
     a.chirality.volume_sign = if_none(chir.new_volume_sign, 0)
     a.chirality.id = if_none(chir.id, "")
     alts.append(a)
   for plane in self.get_planes():
     a = geometry_restraints.motif_alteration(
       action="change", operand="planarity")
     a.motif_ids.resize(len(plane.plane_atoms))
     a.set_planarity_atom_actions([if_none(plane_atom.function, "")
       for plane_atom in plane.plane_atoms])
     a.planarity.atom_names = flex.std_string([if_none(plane_atom.atom_id, "")
       for plane_atom in plane.plane_atoms])
     a.planarity.weights = flex.double([esd_as_weight(plane_atom.new_dist_esd)
       for plane_atom in plane.plane_atoms])
     a.planarity.id = plane.plane_id
     alts.append(a)
   result.set_alterations(alts)
   return result
Exemplo n.º 4
0
 def as_geometry_restraints_motif_manipulation(self):
   result = geometry_restraints.motif_manipulation()
   result.id = if_none(self.chem_link.id, "")
   result.description = if_none(self.chem_link.name, "")
   if (self.source_info is not None):
     result.info.append(self.source_info)
   alts = []
   for bond in self.bond_list:
     a = geometry_restraints.motif_alteration(
       action="add", operand="bond")
     a.motif_ids.append(str(if_none(bond.atom_1_comp_id, "")))
     a.motif_ids.append(str(if_none(bond.atom_2_comp_id, "")))
     a.bond.atom_names = [
       if_none(bond.atom_id_1, ""),
       if_none(bond.atom_id_2, "")]
     a.bond.type = if_none(bond.type, "")
     a.bond.distance_ideal = if_none(bond.value_dist, 0)
     a.bond.weight = esd_as_weight(bond.value_dist_esd)
     alts.append(a)
   for angle in self.angle_list:
     a = geometry_restraints.motif_alteration(
       action="add", operand="angle")
     a.motif_ids.append(str(if_none(angle.atom_1_comp_id, "")))
     a.motif_ids.append(str(if_none(angle.atom_2_comp_id, "")))
     a.motif_ids.append(str(if_none(angle.atom_3_comp_id, "")))
     a.angle.atom_names = [
       if_none(angle.atom_id_1, ""),
       if_none(angle.atom_id_2, ""),
       if_none(angle.atom_id_3, "")]
     a.angle.angle_ideal = if_none(angle.value_angle, 0)
     a.angle.weight = esd_as_weight(angle.value_angle_esd)
     alts.append(a)
   for tor in self.tor_list:
     a = geometry_restraints.motif_alteration(
       action="add", operand="dihedral")
     a.motif_ids.append(str(if_none(tor.atom_1_comp_id, "")))
     a.motif_ids.append(str(if_none(tor.atom_2_comp_id, "")))
     a.motif_ids.append(str(if_none(tor.atom_3_comp_id, "")))
     a.motif_ids.append(str(if_none(tor.atom_4_comp_id, "")))
     a.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, "")]
     a.dihedral.angle_ideal = if_none(tor.value_angle, 0)
     a.dihedral.weight = esd_as_weight(tor.value_angle_esd)
     a.dihedral.periodicity = if_none(tor.period, 0)
     a.dihedral.id = if_none(tor.id, "")
     alts.append(a)
   for chir in self.chir_list:
     a = geometry_restraints.motif_alteration(
       action="add", operand="chirality")
     a.motif_ids.append(str(if_none(chir.atom_centre_comp_id, "")))
     a.motif_ids.append(str(if_none(chir.atom_1_comp_id, "")))
     a.motif_ids.append(str(if_none(chir.atom_2_comp_id, "")))
     a.motif_ids.append(str(if_none(chir.atom_3_comp_id, "")))
     a.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, "")]
     a.chirality.volume_sign = if_none(chir.volume_sign, 0)
     a.chirality.id = if_none(chir.id, "")
     alts.append(a)
   for plane in self.get_planes():
     a = geometry_restraints.motif_alteration(
       action="add", operand="planarity")
     for plane_atom in plane.plane_atoms:
       if (plane_atom.atom_comp_id is None):
         a.motif_ids.append("")
       else:
         a.motif_ids.append(str(plane_atom.atom_comp_id))
     a.planarity.atom_names = flex.std_string([if_none(plane_atom.atom_id, "")
       for plane_atom in plane.plane_atoms])
     a.planarity.weights = flex.double([esd_as_weight(plane_atom.dist_esd)
       for plane_atom in plane.plane_atoms])
     a.planarity.id = plane.plane_id
     alts.append(a)
   result.set_alterations(alts)
   return result
Exemplo n.º 5
0
 def as_geometry_restraints_motif_manipulation(self):
     result = geometry_restraints.motif_manipulation()
     result.id = if_none(self.chem_link.id, "")
     result.description = if_none(self.chem_link.name, "")
     if (self.source_info is not None):
         result.info.append(self.source_info)
     alts = []
     for bond in self.bond_list:
         a = geometry_restraints.motif_alteration(action="add",
                                                  operand="bond")
         a.motif_ids.append(str(if_none(bond.atom_1_comp_id, "")))
         a.motif_ids.append(str(if_none(bond.atom_2_comp_id, "")))
         a.bond.atom_names = [
             if_none(bond.atom_id_1, ""),
             if_none(bond.atom_id_2, "")
         ]
         a.bond.type = if_none(bond.type, "")
         a.bond.distance_ideal = if_none(bond.value_dist, 0)
         a.bond.weight = esd_as_weight(bond.value_dist_esd)
         alts.append(a)
     for angle in self.angle_list:
         a = geometry_restraints.motif_alteration(action="add",
                                                  operand="angle")
         a.motif_ids.append(str(if_none(angle.atom_1_comp_id, "")))
         a.motif_ids.append(str(if_none(angle.atom_2_comp_id, "")))
         a.motif_ids.append(str(if_none(angle.atom_3_comp_id, "")))
         a.angle.atom_names = [
             if_none(angle.atom_id_1, ""),
             if_none(angle.atom_id_2, ""),
             if_none(angle.atom_id_3, "")
         ]
         a.angle.angle_ideal = if_none(angle.value_angle, 0)
         a.angle.weight = esd_as_weight(angle.value_angle_esd)
         alts.append(a)
     for tor in self.tor_list:
         a = geometry_restraints.motif_alteration(action="add",
                                                  operand="dihedral")
         a.motif_ids.append(str(if_none(tor.atom_1_comp_id, "")))
         a.motif_ids.append(str(if_none(tor.atom_2_comp_id, "")))
         a.motif_ids.append(str(if_none(tor.atom_3_comp_id, "")))
         a.motif_ids.append(str(if_none(tor.atom_4_comp_id, "")))
         a.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, "")
         ]
         a.dihedral.angle_ideal = if_none(tor.value_angle, 0)
         a.dihedral.weight = esd_as_weight(tor.value_angle_esd)
         a.dihedral.periodicity = if_none(tor.period, 0)
         a.dihedral.id = if_none(tor.id, "")
         alts.append(a)
     for chir in self.chir_list:
         a = geometry_restraints.motif_alteration(action="add",
                                                  operand="chirality")
         a.motif_ids.append(str(if_none(chir.atom_centre_comp_id, "")))
         a.motif_ids.append(str(if_none(chir.atom_1_comp_id, "")))
         a.motif_ids.append(str(if_none(chir.atom_2_comp_id, "")))
         a.motif_ids.append(str(if_none(chir.atom_3_comp_id, "")))
         a.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, "")
         ]
         a.chirality.volume_sign = if_none(chir.volume_sign, 0)
         a.chirality.id = if_none(chir.id, "")
         alts.append(a)
     for plane in self.get_planes():
         a = geometry_restraints.motif_alteration(action="add",
                                                  operand="planarity")
         for plane_atom in plane.plane_atoms:
             if (plane_atom.atom_comp_id is None):
                 a.motif_ids.append("")
             else:
                 a.motif_ids.append(str(plane_atom.atom_comp_id))
         a.planarity.atom_names = flex.std_string([
             if_none(plane_atom.atom_id, "")
             for plane_atom in plane.plane_atoms
         ])
         a.planarity.weights = flex.double([
             esd_as_weight(plane_atom.dist_esd)
             for plane_atom in plane.plane_atoms
         ])
         a.planarity.id = plane.plane_id
         alts.append(a)
     result.set_alterations(alts)
     return result
Exemplo n.º 6
0
 def as_geometry_restraints_motif_manipulation(self):
     result = geometry_restraints.motif_manipulation()
     result.id = if_none(self.chem_mod.id, "")
     result.description = if_none(self.chem_mod.name, "")
     if (self.source_info is not None):
         result.info.append(self.source_info)
     alts = []
     for atom in self.atom_list:
         a = geometry_restraints.motif_alteration(action=if_none(
             atom.function, ""),
                                                  operand="atom")
         a.motif_ids.append("")
         if (a.action != "add"):
             a.motif_atom_name = if_none(atom.atom_id, "")
         a.atom.name = if_none(atom.new_atom_id, "")
         a.atom.scattering_type = if_none(atom.new_type_symbol, "")
         a.atom.nonbonded_type = if_none(atom.new_type_energy, "")
         a.atom.partial_charge = if_none(atom.new_partial_charge, 0)
         if (a.action == "change"):
             a.set_change_partial_charge(
                 state=atom.new_partial_charge is not None)
         alts.append(a)
     for bond in self.bond_list:
         a = geometry_restraints.motif_alteration(action=if_none(
             bond.function, ""),
                                                  operand="bond")
         a.motif_ids.append("")
         a.motif_ids.append("")
         a.bond.atom_names = [
             if_none(bond.atom_id_1, ""),
             if_none(bond.atom_id_2, "")
         ]
         a.bond.type = if_none(bond.new_type, "")
         a.bond.distance_ideal = if_none(bond.new_value_dist, 0)
         a.bond.weight = esd_as_weight(bond.new_value_dist_esd)
         if (a.action == "change"):
             a.set_change_distance_ideal(
                 state=bond.new_value_dist is not None)
             a.set_change_weight(state=bond.new_value_dist_esd is not None)
         alts.append(a)
     for angle in self.angle_list:
         a = geometry_restraints.motif_alteration(action=if_none(
             bond.function, ""),
                                                  operand="angle")
         a.motif_ids.append("")
         a.motif_ids.append("")
         a.motif_ids.append("")
         a.angle.atom_names = [
             if_none(angle.atom_id_1, ""),
             if_none(angle.atom_id_2, ""),
             if_none(angle.atom_id_3, "")
         ]
         a.angle.angle_ideal = if_none(angle.new_value_angle, 0)
         a.angle.weight = esd_as_weight(angle.new_value_angle_esd)
         if (a.action == "change"):
             a.set_change_angle_ideal(
                 state=angle.new_value_angle is not None)
             a.set_change_weight(
                 state=angle.new_value_angle_esd is not None)
         alts.append(a)
     for tor in self.tor_list:
         a = geometry_restraints.motif_alteration(action=if_none(
             tor.function, ""),
                                                  operand="dihedral")
         a.motif_ids.append("")
         a.motif_ids.append("")
         a.motif_ids.append("")
         a.motif_ids.append("")
         a.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, "")
         ]
         a.dihedral.angle_ideal = if_none(tor.new_value_angle, 0)
         a.dihedral.weight = esd_as_weight(tor.new_value_angle_esd)
         a.dihedral.periodicity = if_none(tor.new_period, 0)
         a.dihedral.id = if_none(tor.id, "")
         if (a.action == "change"):
             a.set_change_angle_ideal(state=tor.new_value_angle is not None)
             a.set_change_weight(state=tor.new_value_angle_esd is not None)
             a.set_change_periodicity(state=tor.new_period is not None)
         alts.append(a)
     for chir in self.chir_list:
         a = geometry_restraints.motif_alteration(action=if_none(
             chir.function, ""),
                                                  operand="chirality")
         a.motif_ids.append("")
         a.motif_ids.append("")
         a.motif_ids.append("")
         a.motif_ids.append("")
         a.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, "")
         ]
         a.chirality.volume_sign = if_none(chir.new_volume_sign, 0)
         a.chirality.id = if_none(chir.id, "")
         alts.append(a)
     for plane in self.get_planes():
         a = geometry_restraints.motif_alteration(action="change",
                                                  operand="planarity")
         a.motif_ids.resize(len(plane.plane_atoms))
         a.set_planarity_atom_actions([
             if_none(plane_atom.function, "")
             for plane_atom in plane.plane_atoms
         ])
         a.planarity.atom_names = flex.std_string([
             if_none(plane_atom.atom_id, "")
             for plane_atom in plane.plane_atoms
         ])
         a.planarity.weights = flex.double([
             esd_as_weight(plane_atom.new_dist_esd)
             for plane_atom in plane.plane_atoms
         ])
         a.planarity.id = plane.plane_id
         alts.append(a)
     result.set_alterations(alts)
     return result
Exemplo n.º 7
0
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()