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)"})
Example #2
0
    def _test_positions(self, atoms):

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

        mol_data = mols.get_data()

        target = mol_data[randrange(len(mol_data))]

        atom_ids = set(target["atom-ids"])
        atom_data = atoms.get_data()

        tmpm = 0.0
        tmpx = 0.0
        tmpy = 0.0
        tmpz = 0.0

        for atom in atom_data:

            if atom["id"] in atom_ids:

                m = atom["mass"]

                tmpm += m
                tmpx += m * atom["xu"]
                tmpy += m * atom["yu"]
                tmpz += m * atom["zu"]

        tmpx /= tmpm
        tmpy /= tmpm
        tmpz /= tmpm

        self.assertEqual(target["xu"], tmpx)
        self.assertEqual(target["yu"], tmpy)
        self.assertEqual(target["zu"], tmpz)
  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)"})
Example #4
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())))
Example #7
0
    def test_error01(self):

        atoms = create(StaDumpAtoms("dumps_bead/bead.2990000.dump", 2990000))
        molecules = create(StaMolecules(atoms))

        molecules.append_updater(AddCoMPosition(atoms))

        self.check_error_msg(
            "RuntimeError: Missing key(s) 'mass' in AddCoMPosition",
            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"])))
Example #9
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)
Example #10
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"])
Example #11
0
  def test_random(self):

    rs = 10*np.random.random_sample((10, 3)) - 5
    ms = np.random.random_sample(10) + 1
    com = (rs.T*ms).T.sum(axis=0)/ms.sum()

    expected = rs - com

    abst_atoms_in_mol = [
      {
        "id": i+1,
        "mol": 1,
        "mass": ms[i],
        "xu": rs[i,0],
        "yu": rs[i,1],
        "zu": rs[i,2]
      }
      for i in range(10)]

    abst_atoms = []

    for imol in range(100):

      tmp = deepcopy(abst_atoms_in_mol)

      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"] += 10*imol
        atom["mol"] += imol
        atom["xu"] += shift_x
        atom["yu"] += shift_y
        atom["zu"] += shift_z

      abst_atoms.extend(tmp)

    atoms = create(StaCustom(abst_atoms))

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

    data = moles.get_data()

    for d in data:

      self.assertTrue(np.allclose(expected, np.array(
        [d["atom-xs"], d["atom-ys"], d["atom-zs"]]).T))
Example #12
0
    def test_beads(self):

        abst_atoms = []
        atom_id = 0

        for imol in range(10):
            for iatom in range(20):

                atom_id += 1

                abst_atoms.append({
                    "id": atom_id,
                    "mol": imol + 1,
                    "mass": 1.0,
                    "xu": float(iatom // 4)
                })

                if iatom % 4 == 0:
                    abst_atoms[-1]["yu"] = 1.0
                    abst_atoms[-1]["zu"] = float(imol) * 10
                elif iatom % 4 == 1:
                    abst_atoms[-1]["yu"] = 0.0
                    abst_atoms[-1]["zu"] = -1.0 + float(imol) * 10
                elif iatom % 4 == 2:
                    abst_atoms[-1]["yu"] = -1.0
                    abst_atoms[-1]["zu"] = float(imol) * 10
                elif iatom % 4 == 3:
                    abst_atoms[-1]["yu"] = 0.0
                    abst_atoms[-1]["zu"] = 1.0 + float(imol) * 10

        atoms = create(StaCustom(abst_atoms))
        moles = create(StaMolecules(atoms))
        beads = create(
            StaBeads(moles, [{
                "indices-in-mol": list(range(4 * i, 4 * (i + 1)))
            } for i in range(5)]))

        beads.append_updater(AddCoMPosition(atoms))

        rs = beads.get_2d_float("xu", "yu", "zu")

        expected_rs = []

        for imol in range(10):
            for ibead in range(5):

                expected_rs.append([float(ibead), 0.0, 10.0 * imol])

        self.assertTrue(np.allclose(rs, np.array(expected_rs)))
    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)