Beispiel #1
0
    def test_atom_id(self):

        atoms = create(StaDumpAtoms("dumps_atom/atom.0.dump", 0))
        moles = create(StaMolecules(atoms))

        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,
            "weights": [1.0] * len(mapping)
        } for mapping in mappings]

        beads = create(StaBeads(moles, abst_beads))

        self.assertEqual(beads.get_keys(),
                         {"id", "mol", "type", "atom-ids", "atom-weights"})

        data = beads.get_data()

        for d in data:

            offset = (d["mol"] - 1) * 38
            in_mol = (d["id"] - 1) % 4

            self.assertEqual(d["atom-ids"],
                             [offset + i + 1 for i in mappings[in_mol]])
Beispiel #2
0
    def test_error01(self):

        atoms = create(StaDumpAtoms("dumps_atom/atom.0.dump", 0))
        moles = create(StaMolecules(atoms))

        self.check_error_msg(
            "RuntimeError: Mapping to beads must be specified by 'indices-in-mol'",
            create, StaBeads(moles, [{
                "foo": [1, 2, 3]
            }]))
    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 #4
0
    def test_error02(self):

        atoms = create(StaDumpAtoms("dumps_atom/atom.0.dump", 0))
        moles = create(StaMolecules(atoms))

        self.check_error_msg(
            "RuntimeError: The numbers of elements in 'indices-in-mol' and 'weights' are inconsistent",
            create,
            StaBeads(moles, [{
                "indices-in-mol": [1, 2, 3, 4],
                "weights": [1.0, 1.0, 1.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)))
Beispiel #6
0
    def test_error03(self):

        atoms = create(StaDumpAtoms("dumps_atom/atom.0.dump", 0))
        moles = create(StaMolecules(atoms))

        check_error_msg(
            self, "RuntimeError: The number of 'type' is invalid", create,
            StaBeads(moles, [{
                "indices-in-mol": [1, 2],
                "weights": [1.0, 1.0]
            }, {
                "indices-in-mol": [3, 4],
                "type": 1,
                "weights": [1.0, 1.0]
            }]))
Beispiel #7
0
    def test_error04(self):

        atoms = create(StaDumpAtoms("dumps_atom/atom.0.dump", 0))
        moles = create(StaMolecules(atoms))

        check_error_msg(
            self, "RuntimeError: The number of 'weights' is invalid", create,
            StaBeads(
                moles, {
                    1: [{
                        "indices-in-mol": [1, 2]
                    }, {
                        "indices-in-mol": [3, 4, 5]
                    }],
                    2: [{
                        "indices-in-mol": [1, 2, 3],
                        "weights": [1.0, 1.0, 1.0]
                    }, {
                        "indices-in-mol": [3, 4],
                        "weights": [1.0, 1.0]
                    }]
                }))