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)) check_error_msg( self, "RuntimeError: Missing key(s) 'hi_x', 'hi_y', 'hi_z', 'lo_x', 'lo_y', 'lo_z' in AddWrappedPosition", atoms.get_data)
def _test_2way_molecules(self, arguments, mol_ids): atoms = create(StaDumpAtoms(*arguments)) mols1 = create(StaMolecules(atoms)) mols2 = create(StaCustom([{"id": i} for i in mol_ids])) mols2.append_updater(AddChildIDs(atoms, "atom", "mol")) self.assertEqual(mols1.get_data(), mols2.get_data())
def test_error01(self): atoms = create(StaDumpAtoms("dumps_bead/bead.2990000.dump", 2990000)) molecules = create(StaMolecules(atoms)) molecules.append_updater(AddCoMPosition(atoms)) check_error_msg( self, "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"])))
def test_error01(self): atoms = create(StaDumpAtoms("dumps_atom/atom.0.dump", 0)) moles = create(StaMolecules(atoms)) check_error_msg( self, "RuntimeError: Mapping to Beads must be specified by 'indices-in-mol'", create, StaBeads(moles, [{ "foo": [1, 2, 3] }]))
def _test_get_2d_float(self, arguments, keys): atoms = create(StaDumpAtoms(*arguments)) data = atoms.get_data() arr = atoms.get_2d_float(*keys) for i in range(10): idx = randrange(len(data)) d = data[idx] self.assertTrue( np.allclose(np.array([d[k] for k in keys]), arr[idx]))
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_equivalent_filter(self, arguments, filter1, filter2): atoms = create(StaDumpAtoms(*arguments)) filtered_atoms1 = create(StaCopy(atoms)).append_updater( FilSet(filter1)) filtered_atoms2 = create(StaCopy(atoms)).append_updater( FilSet(filter2)) self.assertEqual(filtered_atoms1.get_data(), filtered_atoms2.get_data()) self.assertEqual(filtered_atoms1.get_keys(), filtered_atoms2.get_keys())
def _test_get_1d_float(self, arguments, key): atoms = create(StaDumpAtoms(*arguments)) data = atoms.get_data() vec = atoms.get_1d_float(key) for i in range(10): idx = randrange(len(data)) d = data[idx][key] self.assertEqual(d, vec[idx]) self.assertTrue(isinstance(d, float))
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] }]))
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))
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] }] }))
def _test_remaining_number(self, arguments, filterset, num): atoms = create(StaDumpAtoms(*arguments)) atoms.append_updater(FilSet(filterset)) self.assertEqual(len(atoms.get_data()), num)
def _test_get_keys(self, arguments, expectation): molecules = create(StaMolecules(create(StaDumpAtoms(*arguments)))) self.assertEqual(molecules.get_keys(), expectation)
def _test_get_data(self, arguments, indices, expectation): atoms = create(StaDumpAtoms(*arguments)) data = atoms.get_data() self.assertEqual([data[i] for i in indices], expectation)
def test_error01(self): atoms = create(StaDumpAtoms("dummy.file", 0)) check_error_msg(self, "RuntimeError: No such a file 'dummy.file'", atoms.get_data)
def _test_get_keys(self, arguments, expectation): atoms = create(StaDumpAtoms(*arguments)) self.assertEqual(atoms.get_keys(), expectation)