def test_to_from_file_complex(tmp_path, dtype): p = tmp_path / ("water." + dtype) water_dimer_minima.to_file(p) mol = Molecule.from_file(p) assert mol == water_dimer_minima
def test_from_file_json(tmp_path): p = tmp_path / "water.json" p.write_text(water_dimer_minima.json()) mol = Molecule.from_file(p) assert mol.compare(water_dimer_minima)
def test_from_file_string(tmp_path): p = tmp_path / "water.psimol" p.write_text(water_dimer_minima.to_string("psi4")) mol = Molecule.from_file(p) assert mol.compare(water_dimer_minima) assert mol.compare(water_dimer_minima.dict())
def test_from_file_numpy(tmp_path): ele = np.array(water_molecule.atomic_numbers).reshape(-1, 1) npwater = np.hstack((ele, water_molecule.geometry)) # Try npy p = tmp_path / "water.npy" np.save(p, npwater) mol = Molecule.from_file(p) assert mol.compare(water_molecule)
def test_to_from_file_simple(tmp_path, dtype, filext): benchmol = Molecule.from_data(""" O 0 0 0 H 0 1.5 0 H 0 0 1.5 """) p = tmp_path / ("water." + filext) benchmol.to_file(p) mol = Molecule.from_file(p) assert mol == benchmol
def test_to_from_file_charge_spin(tmp_path, dtype, filext): benchmol = Molecule.from_data(""" 1 2 O 0 0 0 H 0 1.5 0 H 0 0 1.5 """) p = tmp_path / ("water." + filext) benchmol.to_file(p, dtype=dtype) mol = Molecule.from_file(p, dtype=dtype) assert mol.molecular_charge == 1 assert mol.molecular_multiplicity == 2 assert mol.fragment_charges[0] == 1 assert mol.fragment_multiplicities[0] == 2 assert mol == benchmol