def test_cubic_isotropic(self):

    abst_atoms = []
    mol_id = 0

    for ix in range(10):
      for iy in range(10):
        for iz in range(10):

          mol_id += 1

          abst_atoms.extend(
            self.create_rotated_abst_atoms_in_mol(
              uniform(-0.5, 0.5), 6*(mol_id-1)+1, mol_id,
              1.0*ix, 1.0*iy, 1.0*iz))

    atoms = create(StaCustom(abst_atoms))

    mols = create(StaMolecules(atoms))
    mols.append_updater(AddCoMPosition(atoms))
    mols.append_updater(AddInertiaMoment(atoms))

    box = create(StaCustom({
      "lo_x": 0.0, "hi_x": 10.0, "pbc_x": True,
      "lo_y": 0.0, "hi_y": 10.0, "pbc_y": True,
      "lo_z": 0.0, "hi_z": 10.0, "pbc_z": True}))

    mols.append_updater(AddWrappedPosition(box))

    pro = ProRDFWD(mols, box)

    num_bins = 20
    bin_width = 0.1

    pro.set_bin(bin_width, num_bins)

    execute_omp(pro)

    self.assertTrue(np.allclose(
      pro.get_r_axis(), np.arange(0.0, num_bins*bin_width, bin_width)))

    expected_rdf = np.zeros(num_bins)

    data = [
      {"index": 10, "num": 6},
      {"index": 14, "num": 12},
      {"index": 17, "num": 8}]

    for d in data:

      r_inner = (d["index"]-0.5) * bin_width
      r_outer = (d["index"]+0.5) * bin_width

      dV = (4.0*np.pi/3.0) * (
        np.power(r_outer, 3) - np.power(r_inner, 3))

      expected_rdf[d["index"]] = (d["num"]/dV)/1.0

    self.assertTrue(np.allclose(pro.get_rdf(), expected_rdf))
  def test_with_and_without_modification(self):

    n_traj = 100
    n_mols = 100

    abst_atoms_traj = []
    mol_id = 0

    for i in range(n_traj):

      abst_atoms = []
      mol_id = 0

      for i in range(n_mols):

        mol_id += 1

        abst_atoms.extend(
          self.create_rotated_abst_atoms_in_mol(
            uniform(-1.0, 1.0), 6*(mol_id-1)+1, mol_id,
            uniform(-50.0, 50.0),
            uniform(-50.0, 50.0),
            uniform(-50.0, 50.0)))

      abst_atoms_traj.append(abst_atoms)

    atomses = [
      create(StaCustom(abst_atoms)) for abst_atoms in abst_atoms_traj]

    boxes = [
      create(StaCustom({
        "lo_x": 0.0, "hi_x": 10.0, "pbc_x": True,
        "lo_y": 0.0, "hi_y": 10.0, "pbc_y": True,
        "lo_z": 0.0, "hi_z": 10.0, "pbc_z": True
      })) for i in range(n_traj)]

    molses = [
      create(StaMolecules(atoms))
        .append_updater(AddCoMPosition(atoms))
        .append_updater(AddInertiaMoment(atoms))
        .append_updater(AddWrappedPosition(box))
      for atoms, box in zip(atomses, boxes)]

    pro_with_modify = ProRDFWD(list(zip(molses, boxes)))
    pro_without_modify = ProRDF(list(zip(molses, boxes)))

    num_bins = 20
    bin_width = 0.1

    pro_with_modify.set_bin(bin_width, num_bins)
    pro_without_modify.set_bin(bin_width, num_bins)

    execute_omp([pro_with_modify, pro_without_modify])

    self.assertTrue(np.allclose(
      pro_with_modify.get_rdf(), pro_without_modify.get_rdf()))
    self.assertTrue(np.allclose(
      np.array(pro_with_modify.get_rdf_traj()),
      np.array(pro_without_modify.get_rdf_traj())))
コード例 #3
0
    def test_error02(self):

        box = create(StaDumpBox("dumps_bead/bead.2990000.dump", 2990000))
        atoms = create(StaCustom([{"A": i, "B": i * i} for i in range(1000)]))
        atoms.append_updater(AddWrappedPosition(box))

        self.check_error_msg(
            "RuntimeError: Missing key(s) 'xu', 'yu', 'zu' in AddWrappedPosition",
            atoms.get_data)
コード例 #4
0
    def test_error01(self):

        box = create(StaCustom({"foo": 0, "bar": 1}))
        atoms = create(StaDumpAtoms("dumps_bead/bead.2990000.dump", 2990000))
        atoms.append_updater(AddWrappedPosition(box))

        self.check_error_msg(
            "RuntimeError: Missing key(s) 'hi_x', 'hi_y', 'hi_z', 'lo_x', 'lo_y', 'lo_z' in AddWrappedPosition",
            atoms.get_data)
    def test_for_beads(self):

        n_samples = 50
        interval = 1000

        atomses = [
            create(StaDumpAtoms("dumps_atom/atom.{}.dump".format(i), i))
            for i in range(0, n_samples * interval + 1, interval)
        ]
        boxes = [
            create(StaDumpBox("dumps_atom/atom.{}.dump".format(i), i))
            for i in range(0, n_samples * interval + 1, interval)
        ]
        molses = [create(StaMolecules(atoms)) for atoms in atomses]

        mappings = [[0, 1, 2, 12, 13, 14, 15, 16, 17, 18],
                    [3, 4, 5, 19, 20, 21, 22, 23, 24],
                    [6, 7, 8, 25, 26, 27, 28, 29, 30],
                    [9, 10, 11, 31, 32, 33, 34, 35, 36, 37]]

        abst_beads = [{
            "type": 1,
            "indices-in-mol": mapping
        } for mapping in mappings]

        beadses = [
            create(StaBeads(mols, abst_beads)).append_updater(
                AddCoMPosition(atoms)).append_updater(
                    AddInertiaMoment(atoms)).append_updater(
                        AddWrappedPosition(box))
            for atoms, box, mols in zip(atomses, boxes, molses)
        ]

        pro = ProRDFWD(list(zip(beadses, boxes)))

        num_bins = 150
        bin_width = 0.1

        pro.set_bin(bin_width, num_bins)
        pro.set_margin(2.0)

        execute_omp(pro)

        Rg2s = pro.get_squared_gyration_radius()

        self.assertTrue(
            np.allclose(Rg2s["isotropic"], (1 / 3) * Rg2s["parallel"] +
                        (2 / 3) * Rg2s["perpendicular"]))

        Rg2s_traj = pro.get_squared_gyration_radius_traj()

        self.assertTrue(
            np.allclose(np.array(Rg2s_traj["isotropic"]),
                        (1 / 3) * np.array(Rg2s_traj["parallel"]) +
                        (2 / 3) * np.array(Rg2s_traj["perpendicular"])))
コード例 #6
0
    def _test_wrapping(self, arguments):

        box = create(StaDumpBox(*arguments))
        atoms = create(StaDumpAtoms(*arguments))
        atoms.append_updater(AddWrappedPosition(box))

        wrapped = atoms.get_2d_float("x", "y", "z")
        unwrapped = atoms.get_2d_float("xu", "yu", "zu")

        box_data = box.get_data()

        diff = unwrapped - wrapped
        diff_x = diff.T[0] / (box_data["hi_x"] - box_data["lo_x"])
        diff_y = diff.T[1] / (box_data["hi_y"] - box_data["lo_y"])
        diff_z = diff.T[2] / (box_data["hi_z"] - box_data["lo_z"])

        self.assertTrue(np.all(diff_x.round() == diff_x))
        self.assertTrue(np.all(diff_y.round() == diff_y))
        self.assertTrue(np.all(diff_z.round() == diff_z))