Esempio n. 1
0
    def test_with_select(self):

        data = [{"A": i, "B": i * i} for i in range(1000)]
        data2 = [{"A": i, "B": i * i, "C": i * i * i} for i in range(1000)]
        elems = [
            create(StaCustom({
                "A": d["A"],
                "B": d["B"],
                "C": d["A"] + d["B"]
            })) for d in data
        ]

        pro = ProData(elems)
        pro.select("A", "B")

        execute_omp(pro)

        self.assertEqual(pro.get_results(), data)

        data = [[{"A": j, "B": i * j} for j in range(100)] for i in range(100)]
        data2 = [[{
            "A": j,
            "B": i * j,
            "C": i + j
        } for j in range(100)] for i in range(100)]
        elems = [create(StaCustom(d)) for d in data]

        pro = ProData(elems)
        pro.select("A", "B")

        execute_omp(pro)

        self.assertEqual(pro.get_results(), data)
Esempio n. 2
0
  def test_select_two(self):

    ids = list(range(1000))
    shuffle(ids)

    data = [[
      {"id": j, "A": float(i+j), "B": float(i*j)}
      for j in ids]
      for i in range(100)]
    elems = [create(StaCustom(d)) for d in data]

    pro = ProValueArray(elems)
    pro.select("A", "B")

    execute_omp(pro)

    arrs = pro.get_results()

    for i, elem in enumerate(elems):

      ds = elem.get_data()

      for d in ds:
        self.assertEqual(arrs["A"][i][d["id"]], d["A"])
        self.assertEqual(arrs["B"][i][d["id"]], d["B"])
  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())))
    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"])))
Esempio n. 6
0
  def test_rotate_stick(self):

    n_mols = 10

    rotate_data = []
    initial_atoms = []

    for imol in range(n_mols):

      ps = np.random.uniform(-10.0, 10.0, (3,3))

      m_point = 0.5 * (ps[0] + ps[1])

      cross = np.cross(ps[1] - ps[0], ps[2] - ps[0])
      n_vector = cross / np.linalg.norm(cross)

      rotate_data.append({"normal": n_vector, "middle": m_point})

      initial_atoms.extend([
        {"id": 2*imol+i+1, "mol": imol+1, "xyz": ps[i]}
        for i in range(2)
      ])

    atoms_traj = []

    for i in range(181):

      atoms_tmp = deepcopy(initial_atoms)

      for atom in atoms_tmp:

        m = rotate_data[atom["mol"]-1]["middle"]
        n = rotate_data[atom["mol"]-1]["normal"]

        rotated_xyz = np.array(rot(i, n, atom["xyz"]-m)) + m

        atom["xu"] = rotated_xyz[0]
        atom["yu"] = rotated_xyz[1]
        atom["zu"] = rotated_xyz[2]

        del atom["xyz"]

      atoms_traj.append(create(StaCustom(atoms_tmp)))

    mols_traj = [create(StaMolecules(atoms)) for atoms in atoms_traj]

    pro = ProTimeCorrelationInMolecule(list(zip(mols_traj, atoms_traj)))
    pro.set_indices(0, 1)

    execute_omp(pro)

    expects = np.array([np.cos(i*np.pi/180) for i in range(181)])

    self.assertTrue(np.allclose(pro.get_time_correlation(), expects))
    def test_dimension_2d(self):

        abst_atoms_traj = []

        for itraj in range(10):

            tmp = deepcopy(self.abst_atoms)

            shift_x = uniform(-100.0, 100.0)
            shift_y = uniform(-100.0, 100.0)
            shift_z = uniform(-100.0, 100.0)

            for atom in tmp:

                atom["xu"] *= itraj + 1
                atom["yu"] *= itraj + 1
                atom["zu"] *= itraj + 1

                atom["xu"] += shift_x
                atom["yu"] += shift_y
                atom["zu"] += shift_z

            abst_atoms_traj.append(tmp)

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

        pro_xyz = ProMeanSquareDisplacement(atomses)

        pro_xy = ProMeanSquareDisplacement(atomses)
        pro_xy.set_dimension(True, True, False)

        pro_yz = ProMeanSquareDisplacement(atomses)
        pro_yz.set_dimension(False, True, True)

        pro_xz = ProMeanSquareDisplacement(atomses)
        pro_xz.set_dimension(True, False, True)

        execute_omp([pro_xyz, pro_xy, pro_yz, pro_xz])

        self.assertTrue(
            np.allclose(pro_xy.get_mean_square_displacement(),
                        pro_yz.get_mean_square_displacement()))

        self.assertTrue(
            np.allclose(pro_xy.get_mean_square_displacement(),
                        pro_xz.get_mean_square_displacement()))

        self.assertTrue(
            np.allclose(
                2 * pro_xyz.get_mean_square_displacement(),
                pro_xz.get_mean_square_displacement() +
                pro_yz.get_mean_square_displacement() +
                pro_xz.get_mean_square_displacement()))
    def test_dimension_3d(self):

        abst_atoms_traj = []

        for itraj in range(10):

            tmp = deepcopy(self.abst_atoms)

            shift_x = uniform(-100.0, 100.0)
            shift_y = uniform(-100.0, 100.0)
            shift_z = uniform(-100.0, 100.0)

            for atom in tmp:

                atom["xu"] *= itraj + 1
                atom["yu"] *= itraj + 1
                atom["zu"] *= itraj + 1

                atom["xu"] += shift_x
                atom["yu"] += shift_y
                atom["zu"] += shift_z

            abst_atoms_traj.append(tmp)

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

        pro = ProMeanSquareDisplacement(atomses)

        execute_omp(pro)

        expect = np.array([2.0 * i * i for i in range(10)])

        self.assertTrue(np.allclose(pro.get_mean_square_displacement(),
                                    expect))

        expect_array = []

        for itraj in range(10):

            tmp = []

            for i in range(-1, 2):
                for j in range(-1, 2):
                    for k in range(-1, 2):

                        tmp.append(
                            float(i * i + j * j + k * k) * itraj * itraj)

            expect_array.append(tmp)

        self.assertTrue(
            np.allclose(pro.get_displacement2_array(), np.array(expect_array)))
Esempio n. 9
0
    def test_20x30_with_shift(self):

        atoms = [
            create(
                StaCustom([{
                    "x": 1.0 * ix,
                    "y": 1.0 * iy - 10.0,
                    "z": 1.0 * i,
                    "radius": 1.0
                } for ix in range(20) for iy in range(30)])) for i in range(10)
        ]
        box = [
            create(
                StaCustom({
                    "lo_x": 0.0,
                    "hi_x": 20.0,
                    "lo_y": -10.0,
                    "hi_y": 20.0
                })) for i in range(10)
        ]

        pro = ProThicknessProfile(list(zip(atoms, box)))
        pro.set_grid(20, 30)
        pro.shift_half_delta()

        execute_omp(pro)

        conditions = pro.get_conditions()

        for c in conditions:

            self.assertEqual(
                c, {
                    "origin_x": 0.5,
                    "origin_y": -9.5,
                    "delta_x": 1.0,
                    "delta_y": 1.0,
                    "nx": 20,
                    "ny": 30
                })

        profiles = pro.get_profiles()

        addition = 0.5 * sqrt(2)

        for i, p in enumerate(profiles):

            self.assertTrue(
                np.allclose(p, np.full((20, 30),
                                       float(i) + addition)))
    def test_squared_distance(self):

        abst_atoms = []
        n_atoms_in_mol = len(self.base_data)

        for imol in range(10):

            tmp = deepcopy(self.base_data)

            shift_x = uniform(-100.0, 100.0)
            shift_y = uniform(-100.0, 100.0)
            shift_z = uniform(-100.0, 100.0)

            for atom in tmp:

                atom["id"] += imol * n_atoms_in_mol
                atom["mol"] += imol
                atom["xu"] += shift_x
                atom["yu"] += shift_y
                atom["zu"] += shift_z

            abst_atoms.extend(tmp)

        abst_atoms_traj = []

        for itraj in range(10):

            tmp = deepcopy(abst_atoms)

            for atom in tmp:
                atom["xu"] *= itraj + 1
                atom["yu"] *= itraj + 1
                atom["zu"] *= itraj + 1

            abst_atoms_traj.append(tmp)

        atomses = [create(StaCustom(a)) for a in abst_atoms_traj]
        molses = [create(StaMolecules(a)) for a in atomses]

        pro = ProDistanceInMolecule(list(zip(molses, atomses)))
        pro.set_indices(0, 5)

        execute_omp(pro)

        expects = np.array([[20.0 * (i + 1) * (i + 1)] * 10
                            for i in range(10)])

        self.assertTrue(np.allclose(pro.get_distance2_array(), expects))
Esempio n. 11
0
    def test_without_select(self):

        data = [{"A": i, "B": i * i} for i in range(1000)]
        elems = [create(StaCustom(d)) for d in data]

        pro = ProData(elems)

        execute_omp(pro)

        self.assertEqual(pro.get_results(), data)

        data = [[{"A": j, "B": i * j} for j in range(100)] for i in range(100)]
        elems = [create(StaCustom(d)) for d in data]

        pro = ProData(elems)

        execute_omp(pro)

        self.assertEqual(pro.get_results(), data)
Esempio n. 12
0
  def test_select_one(self):

    data = [[
      {"id": j, "A": float(i+j), "B": float(i*j)}
      for j in range(1000)]
      for i in range(100)]
    elems = [create(StaCustom(d)) for d in data]
    pro = ProValueArray(elems)
    pro.select("A")

    execute_omp(pro)

    arr_A = pro.get_results()["A"]

    for i, elem in enumerate(elems):

      ds = elem.get_data()

      for d in ds:
        self.assertEqual(arr_A[i][d["id"]], d["A"])
    def test_cubic(self):

        abst_atoms = []
        atom_id = 0

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

                    atom_id += 1

                    abst_atoms.append({
                        "id": atom_id,
                        "x": 1.0 * ix,
                        "y": 1.0 * iy,
                        "z": 1.0 * iz
                    })

        atoms = create(StaCustom(abst_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
            }))

        pro = ProRadialDistributionFunction(atoms, 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_traj(self):

        atoms_traj = []
        box_traj = []

        for i in range(10):

            abst_atoms = []
            atom_id = 0

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

                        atom_id += 1

                        abst_atoms.append({
                            "id":
                            atom_id,
                            "x":
                            1.0 * (ix + 0.5) + uniform(-0.005, 0.005),
                            "y":
                            1.0 * (iy + 0.5) + uniform(-0.005, 0.005),
                            "z":
                            1.0 * (iz + 0.5) + uniform(-0.005, 0.005)
                        })

            atoms_traj.append(create(StaCustom(abst_atoms)))

            box_traj.append(
                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
                    })))

        pro = ProRadialDistributionFunction(list(zip(atoms_traj, box_traj)))

        num_bins = 20
        bin_width = 0.1

        pro.set_bin(bin_width, num_bins)

        execute_omp(pro)

        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

        rdf = pro.get_rdf()

        self.assertTrue(np.allclose(rdf, expected_rdf))

        rdf_traj = pro.get_rdf_traj()

        rdf_sum = np.zeros(num_bins)

        for rdf_tmp in rdf_traj:

            self.assertTrue(np.allclose(rdf_tmp, expected_rdf))

            rdf_sum += rdf_tmp

        self.assertTrue(np.allclose(len(rdf_traj) * rdf, rdf_sum))