def test_sqrted(self):

    atoms = create(StaCustom(self.custom_data))
    molecules = create(StaMolecules(atoms))
    molecules.append_updater(AddCoMPosition(atoms))
    molecules.append_updater(AddInertiaMoment(atoms))
    molecules.append_updater(AddGyrationRadius().with_sqrted())

    data = molecules.get_data()[0]

    self.assertAlmostEqual(data["Rg"], 1.0)
    self.assertAlmostEqual(data["Rg(x+y)"], sqrt(2/3))
    self.assertAlmostEqual(data["Rg(x)"], sqrt(1/3))

    self.assertEqual(data["Rg(x+y)"], data["Rg(y+z)"])
    self.assertEqual(data["Rg(x+y)"], data["Rg(z+x)"])

    self.assertEqual(data["Rg(x)"], data["Rg(y)"])
    self.assertEqual(data["Rg(x)"], data["Rg(z)"])

    self.assertEqual(
      molecules.get_keys(), {
        "id", "atom-ids", "mass", "xu", "yu", "zu",
        "I_xx", "I_yy", "I_zz", "I_xy", "I_xz", "I_yz",
        "Rg^2", "Rg^2(y+z)", "Rg^2(z+x)", "Rg^2(x+y)",
        "Rg^2(x)", "Rg^2(y)", "Rg^2(z)",
        "Rg", "Rg(y+z)", "Rg(z+x)", "Rg(x+y)",
        "Rg(x)", "Rg(y)", "Rg(z)"})
  def test_squared(self):

    custom_data = deepcopy(self.custom_data)

    custom_data[0]["xu"] = 3.0
    custom_data[1]["xu"] = -1.0

    atoms = create(StaCustom(custom_data))
    molecules = create(StaMolecules(atoms))
    molecules.append_updater(AddCoMPosition(atoms))
    molecules.append_updater(AddInertiaMoment(atoms))
    molecules.append_updater(AddGyrationRadius())

    data = molecules.get_data()[0]

    self.assertAlmostEqual(data["Rg^2"], 2.0)
    self.assertAlmostEqual(data["Rg^2(x+y)"], 5/3)
    self.assertAlmostEqual(data["Rg^2(y+z)"], 2/3)
    self.assertAlmostEqual(data["Rg^2(z+x)"], 5/3)
    self.assertAlmostEqual(data["Rg^2(x)"], 4/3)
    self.assertAlmostEqual(data["Rg^2(y)"], 1/3)
    self.assertAlmostEqual(data["Rg^2(z)"], 1/3)

    self.assertEqual(
      molecules.get_keys(), {
        "id", "atom-ids", "mass", "xu", "yu", "zu",
        "I_xx", "I_yy", "I_zz", "I_xy", "I_xz", "I_yz",
        "Rg^2", "Rg^2(y+z)", "Rg^2(z+x)", "Rg^2(x+y)",
        "Rg^2(x)", "Rg^2(y)", "Rg^2(z)"})
Beispiel #3
0
  def test_gyration_radius(self):

    n_samples = 2000

    rs = 100*np.random.random_sample((n_samples, 3)) - 50

    abst_atoms = [
      {
        "id": i+1,
        "mol": i//20 + 1,
        "mass": 12.011,
        "xu": rs[i,0],
        "yu": rs[i,1],
        "zu": rs[i,2]
      }
      for i in range(2000)]

    atoms = create(StaCustom(abst_atoms))

    moles = create(StaMolecules(atoms))
    moles.append_updater(AddCoMPosition(atoms))
    moles.append_updater(AddChildPositions(atoms, "atom"))

    moles.append_updater(AddInertiaMoment(atoms))
    moles.append_updater(AddGyrationRadius())

    data = moles.get_data()

    for d in data:

      xyzs = d["atom-xs"] + d["atom-ys"] + d["atom-zs"]

      self.assertAlmostEqual(
        d["Rg^2"], sum([a*a for a in xyzs])/len(d["atom-ids"]))
  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())))
Beispiel #6
0
  def test_error02(self):

    atoms = create(StaCustom(self.custom_data))
    molecules = create(StaMolecules(atoms))
    molecules.append_updater(AddInertiaMoment(atoms))

    check_error_msg(
      self,  "RuntimeError: Missing key(s) 'xu', 'yu', 'zu' in AddInertiaMoment", molecules.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"])))
Beispiel #8
0
  def test_error01(self):

    atoms = create(StaCustom(self.custom_data))
    molecules = create(StaMolecules(atoms))
    molecules.append_updater(AddCoMPosition(atoms))

    molecules.append_updater(
      AddInertiaMoment(create(StaCustom({"foo": 0, "bar": 1}))))

    check_error_msg(
      self, "RuntimeError: Missing key(s) 'id', 'mass', 'xu', 'yu', 'zu' in AddInertiaMoment", molecules.get_data)
Beispiel #9
0
  def test_isotropic(self):

    atoms = create(StaCustom(self.custom_data))
    molecules = create(StaMolecules(atoms))
    molecules.append_updater(AddCoMPosition(atoms))
    molecules.append_updater(AddInertiaMoment(atoms))

    data = molecules.get_data()[0]

    self.assertEqual(data["I_xx"], data["I_yy"])
    self.assertEqual(data["I_yy"], data["I_zz"])
    self.assertEqual(data["I_xy"], data["I_xz"])
    self.assertEqual(data["I_xy"], data["I_yz"])
    def test_isotropic(self):

        atoms = create(StaCustom(self.custom_data))
        molecules = create(StaMolecules(atoms))
        molecules.append_updater(AddCoMPosition(atoms))
        molecules.append_updater(AddInertiaMoment(atoms))
        molecules.append_updater(AddMolecularOrientation())

        data = molecules.get_data()[0]

        evals = data["I_values"]
        self.assertEqual(evals[0], evals[1])
        self.assertEqual(evals[0], evals[2])

        evecs = data["I_vectors"]
        self.assertTrue(np.allclose(np.array(evecs), np.identity(3)))
    def test_x_oriented(self):

        atoms = create(
            StaCustom([
                {
                    "id": 1,
                    "mol": 1,
                    "mass": 1.0,
                    "xu": 1.0,
                    "yu": 1.0,
                    "zu": 1.0
                },
                {
                    "id": 2,
                    "mol": 1,
                    "mass": 1.0,
                    "xu": 2.0,
                    "yu": 1.0,
                    "zu": 1.0
                },
                {
                    "id": 3,
                    "mol": 1,
                    "mass": 1.0,
                    "xu": 4.0,
                    "yu": 1.0,
                    "zu": 1.0
                },
                {
                    "id": 4,
                    "mol": 1,
                    "mass": 1.0,
                    "xu": 8.0,
                    "yu": 1.0,
                    "zu": 1.0
                },
            ]))
        molecules = create(StaMolecules(atoms))
        molecules.append_updater(AddCoMPosition(atoms))
        molecules.append_updater(AddInertiaMoment(atoms))
        molecules.append_updater(AddMolecularOrientation())

        data = molecules.get_data()[0]

        self.assertEqual(data["S_x"], 1.0)
        self.assertEqual(data["S_y"], -0.5)
        self.assertEqual(data["S_z"], -0.5)