Exemple #1
0
def setup_bond_params_table(structure, bond_sym_table):
  scatterers = structure.scatterers()
  t = geometry_restraints.bond_params_table(scatterers.size())
  for i_seq,bond_sym_dict in enumerate(bond_sym_table):
    for j_seq in bond_sym_dict.keys():
      i_seqs = [i_seq, j_seq]
      i_seqs.sort()
      scattering_types = [scatterers[i].scattering_type for i in i_seqs]
      scattering_types.sort()
      if (scattering_types == ["Si", "Si"]):
        params = restraint_parameters_si_o_si
      elif (scattering_types == ["O", "Si"]):
        params = restraint_parameters_si_o
      elif (scattering_types == ["O", "O"]):
        params = restraint_parameters_o_si_o
      else:
        raise AssertionError("Unknown scattering type pair.")
      if (not t[i_seq].has_key(j_seq)):
        t[i_seq][j_seq] = geometry_restraints.bond_params(
          distance_ideal=params.distance_ideal,
          weight=params.weight)
      else:
        prev_params = t[i_seq][j_seq]
        assert abs(prev_params.distance_ideal - params.distance_ideal) < 1.e-8
        assert abs(prev_params.weight - params.weight) < 1.e-8
  return t
Exemple #2
0
def exercise_bond_sorted_asu_proxies(structure, distance_cutoff):
    asu_mappings = structure.asu_mappings(buffer_thickness=distance_cutoff)
    bond_asu_table = crystal.pair_asu_table(asu_mappings=asu_mappings)
    bond_asu_table.add_all_pairs(distance_cutoff=distance_cutoff)
    bond_sym_table = bond_asu_table.extract_pair_sym_table()
    el = bond_sym_table.simple_edge_list()
    es = bond_sym_table.full_simple_connectivity()
    assert es.size() == bond_sym_table.size()
    for i, j in el:
        assert j in es[i]
        assert i in es[j]
    npis = bond_sym_table.number_of_pairs_involving_symmetry()
    assert len(list(bond_sym_table.iterator())) == len(el) + npis
    bond_params_table = geometry_restraints.bond_params_table(
        structure.scatterers().size())
    for i_seq, bond_sym_dict in enumerate(bond_sym_table):
        for j_seq in bond_sym_dict.keys():
            if (i_seq > j_seq):
                j_seq, i_seq = i_seq, j_seq
            bond_params_table[i_seq][j_seq] = geometry_restraints.bond_params(
                distance_ideal=3.1, weight=1)
    proxies_fast = geometry_restraints.bond_sorted_asu_proxies(
        bond_params_table=bond_params_table, bond_asu_table=bond_asu_table)
    proxies_conservative = geometry_restraints.bond_sorted_asu_proxies(
        pair_asu_table=bond_asu_table)
    pair_generator = crystal.neighbors_simple_pair_generator(
        asu_mappings=asu_mappings,
        distance_cutoff=distance_cutoff,
        minimal=False)
    proxies_slow = geometry_restraints.bond_sorted_asu_proxies(
        asu_mappings=asu_mappings)
    for pair in pair_generator:
        proxies_slow.process(
            geometry_restraints.bond_asu_proxy(pair=pair,
                                               distance_ideal=3.1,
                                               weight=1))

    def compare_proxies(proxies_1, proxies_2):
        assert proxies_1.simple.size() == proxies_2.simple.size()
        assert proxies_1.asu.size() == proxies_2.asu.size()
        ctrl = {}
        for proxy in proxies_1.simple:
            assert proxy.i_seqs not in ctrl
            ctrl[proxy.i_seqs] = 0
        for proxy in proxies_2.simple:
            assert proxy.i_seqs in ctrl
            ctrl[proxy.i_seqs] += 1
        assert list(ctrl.values()) == [1] * len(ctrl)
        ctrl = {}
        for proxy in proxies_1.asu:
            key = proxy.i_seq, proxy.j_seq, proxy.j_sym
            assert key not in ctrl
            ctrl[key] = 0
        for proxy in proxies_2.asu:
            key = proxy.i_seq, proxy.j_seq, proxy.j_sym
            assert key in ctrl
            ctrl[key] += 1
        assert list(ctrl.values()) == [1] * len(ctrl)

    compare_proxies(proxies_1=proxies_fast, proxies_2=proxies_conservative)
    compare_proxies(proxies_1=proxies_fast, proxies_2=proxies_slow)
    sites_cart = structure.sites_cart()
    for proxy in proxies_conservative.simple:
        i, j = proxy.i_seqs
        assert approx_equal(
            abs(matrix.col(sites_cart[i]) - matrix.col(sites_cart[j])),
            proxy.distance_ideal)
        assert proxy.weight == 1
    distance = proxies_conservative.asu_mappings().unit_cell().distance
    get_rt_mx_ji = proxies_conservative.asu_mappings().get_rt_mx_ji
    sites_frac = structure.sites_frac()
    for proxy in proxies_conservative.asu:
        assert approx_equal(
            distance(sites_frac[proxy.i_seq],
                     get_rt_mx_ji(pair=proxy) * sites_frac[proxy.j_seq]),
            proxy.distance_ideal)
        assert proxy.weight == 1
def exercise_bond_sorted_asu_proxies(
      structure,
      distance_cutoff):
  asu_mappings = structure.asu_mappings(buffer_thickness=distance_cutoff)
  bond_asu_table = crystal.pair_asu_table(asu_mappings=asu_mappings)
  bond_asu_table.add_all_pairs(distance_cutoff=distance_cutoff)
  bond_sym_table = bond_asu_table.extract_pair_sym_table()
  el = bond_sym_table.simple_edge_list()
  es = bond_sym_table.full_simple_connectivity()
  assert es.size() == bond_sym_table.size()
  for i,j in el:
    assert j in es[i]
    assert i in es[j]
  npis = bond_sym_table.number_of_pairs_involving_symmetry()
  assert len(list(bond_sym_table.iterator())) == len(el) + npis
  bond_params_table = geometry_restraints.bond_params_table(
    structure.scatterers().size())
  for i_seq,bond_sym_dict in enumerate(bond_sym_table):
    for j_seq in bond_sym_dict.keys():
      if (i_seq > j_seq):
        j_seq,i_seq = i_seq,j_seq
      bond_params_table[i_seq][j_seq] = geometry_restraints.bond_params(
        distance_ideal=3.1, weight=1)
  proxies_fast = geometry_restraints.bond_sorted_asu_proxies(
    bond_params_table=bond_params_table,
    bond_asu_table=bond_asu_table)
  proxies_conservative = geometry_restraints.bond_sorted_asu_proxies(
    pair_asu_table=bond_asu_table)
  pair_generator = crystal.neighbors_simple_pair_generator(
    asu_mappings=asu_mappings,
    distance_cutoff=distance_cutoff,
    minimal=False)
  proxies_slow = geometry_restraints.bond_sorted_asu_proxies(
    asu_mappings=asu_mappings)
  for pair in pair_generator:
    proxies_slow.process(geometry_restraints.bond_asu_proxy(
      pair=pair,
      distance_ideal=3.1,
      weight=1))
  def compare_proxies(proxies_1, proxies_2):
    assert proxies_1.simple.size() == proxies_2.simple.size()
    assert proxies_1.asu.size() == proxies_2.asu.size()
    ctrl = {}
    for proxy in proxies_1.simple:
      assert not ctrl.has_key(proxy.i_seqs)
      ctrl[proxy.i_seqs] = 0
    for proxy in proxies_2.simple:
      assert ctrl.has_key(proxy.i_seqs)
      ctrl[proxy.i_seqs] += 1
    assert ctrl.values() == [1]*len(ctrl)
    ctrl = {}
    for proxy in proxies_1.asu:
      key = proxy.i_seq,proxy.j_seq,proxy.j_sym
      assert not ctrl.has_key(key)
      ctrl[key] = 0
    for proxy in proxies_2.asu:
      key = proxy.i_seq,proxy.j_seq,proxy.j_sym
      assert ctrl.has_key(key)
      ctrl[key] += 1
    assert ctrl.values() == [1]*len(ctrl)
  compare_proxies(proxies_1=proxies_fast, proxies_2=proxies_conservative)
  compare_proxies(proxies_1=proxies_fast, proxies_2=proxies_slow)
  sites_cart = structure.sites_cart()
  for proxy in proxies_conservative.simple:
    i,j = proxy.i_seqs
    assert approx_equal(
      abs(matrix.col(sites_cart[i]) - matrix.col(sites_cart[j])),
      proxy.distance_ideal)
    assert proxy.weight == 1
  distance = proxies_conservative.asu_mappings().unit_cell().distance
  get_rt_mx_ji = proxies_conservative.asu_mappings().get_rt_mx_ji
  sites_frac = structure.sites_frac()
  for proxy in proxies_conservative.asu:
    assert approx_equal(
      distance(
        sites_frac[proxy.i_seq],
        get_rt_mx_ji(pair=proxy) * sites_frac[proxy.j_seq]),
      proxy.distance_ideal)
    assert proxy.weight == 1