def test_sparse_molecule_connectivity(): """ A bit of a weird test, but because we set connectivity it should carry through. """ mol = Molecule(symbols=["He", "He"], geometry=[0, 0, -2, 0, 0, 2], connectivity=None) assert "connectivity" in mol.dict() assert mol.dict()["connectivity"] is None mol = Molecule(symbols=["He", "He"], geometry=[0, 0, -2, 0, 0, 2]) assert "connectivity" not in mol.dict()
def test_molecule_sparsity(): m = Molecule(**{"symbols": ["He"], "geometry": [0, 0, 0]}) assert set(m.dict().keys()) == {"symbols", "geometry"} m = Molecule( **{ "symbols": ["He"], "geometry": [0, 0, 0], "identifiers": { "molecular_formula": "He" } }) assert set(m.dict().keys()) == {"symbols", "geometry", "identifiers"} assert set(m.dict()["identifiers"].keys()) == {"molecular_formula"} assert set(m.identifiers.dict().keys()) == {"molecular_formula"}
def test_molecule_repeated_hashing(): mol = Molecule(**{ 'symbols': ['H', 'O', 'O', 'H'], 'geometry': [ 1.7317, 1.2909, 1.037100000000001, 1.3156, -0.0074, -0.2807, -1.3143, 0.0084, -0.2741, -1.7241, -1.3079, 1.0277 ] }) # yapf: disable h1 = mol.get_hash() assert mol.get_molecular_formula() == "H2O2" mol2 = Molecule(orient=False, **mol.dict()) assert h1 == mol2.get_hash() mol3 = Molecule(orient=False, **mol2.dict()) assert h1 == mol3.get_hash()
def test_molecule_repeated_hashing(): mol = Molecule( **{ "symbols": ["H", "O", "O", "H"], "geometry": [ [1.7317, 1.2909, 1.037100000000001], [1.3156, -0.0074, -0.2807], [-1.3143, 0.0084, -0.2741], [-1.7241, -1.3079, 1.0277], ], }) h1 = mol.get_hash() assert mol.get_molecular_formula() == "H2O2" mol2 = Molecule(orient=False, **mol.dict()) assert h1 == mol2.get_hash() mol3 = Molecule(orient=False, **mol2.dict()) assert h1 == mol3.get_hash()
def test_molecule_skip_defaults(water): mol = Molecule(**{"symbols": ["He"], "geometry": [0, 0, 0]}, validate=False) assert {"symbols", "geometry"} == mol.dict().keys()