def saved_db(): """Create and return a SystemDB object with the database file.""" db = SystemDB(filename="seamm.db") yield db db.close()
def test_system(): """Test that we can get a System object""" db = SystemDB(filename="file:seamm_db?mode=memory&cache=shared") system = db.create_system(name="default") assert str(type(system)) == "<class 'molsystem.system._System'>" assert system.n_configurations == 0 db.close()
def disk_db(db_file): """Create and return a SystemDB object with the database file.""" db = SystemDB(filename=db_file) yield db db.close()
def test_bonds(): """Test that we can get an Bonds object""" db = SystemDB(filename="file:seamm_db?mode=memory&cache=shared") system = db.create_system(name="default") configuration = system.create_configuration() bonds = configuration.bonds assert str(type(bonds)) == "<class 'molsystem.bonds._Bonds'>" db.close()
def test_atoms(): """Test that we can get an Atoms object""" db = SystemDB(filename="file:seamm_db?mode=memory&cache=shared") system = db.create_system(name="default") configuration = system.create_configuration() atoms = configuration.atoms assert str(type(atoms)) == "<class 'molsystem.atoms._Atoms'>" db.close()
def test_configuration(): """Test that we can get a Configuration object""" db = SystemDB(filename="file:seamm_db?mode=memory&cache=shared") system = db.create_system(name="default") configuration = system.create_configuration() _type = str(type(configuration)) assert _type == "<class 'molsystem.configuration._Configuration'>" db.close()
def empty_db(): """Create a system db with no systems.""" db = SystemDB(filename="file:seamm_db?mode=memory&cache=shared") yield db db.close() try: del db except: # noqa: E722 print("Caught error deleting the database")
def full_db(): """Create a system database with several systems.""" db = SystemDB(filename="file:seamm_db?mode=memory&cache=shared") for filename in ["acy.mmcif"]: with open(data_path / filename, "r") as fd: text = fd.read() system = db.add_system(name=Path(filename).stem) configuration = system.create_configuration(name="default") configuration.from_mmcif_text(text) yield db db.close()
def db_file(tmp_path_factory): """Create and temporary directory, and clean it up at the end.""" dirpath = tmp_path_factory.mktemp("data") path = dirpath / "seamm.db" db = SystemDB(filename=str(path)) db.close() print(f"temp file: {path}") yield str(path) path.unlink() dirpath.rmdir()
def two_dbs(): """Create two different dbs.""" db1 = SystemDB(filename="file:seamm_db1?mode=memory&cache=shared") system1 = db1.create_system(name="default") system1.create_configuration(name="default") db2 = SystemDB(filename="file:seamm_db2?mode=memory&cache=shared") system2 = db2.create_system(name="default") system2.create_configuration(name="default") yield db1, db2 db1.close() db2.close()
def test_adding_atoms(): """Test that we can add atoms""" db = SystemDB(filename="file:seamm_db?mode=memory&cache=shared") system = db.create_system(name="default") configuration = system.create_configuration() atoms = configuration.atoms symbol = ["Ar"] * 4 X = [2.0, 0.0, -2.0, 0.0] Y = [0.0, 2.0, 0.0, -2.0] Z = [0.0] * 4 ids = atoms.append(symbol=symbol, x=X, y=Y, z=Z) assert atoms.n_atoms == 4 assert ids == [1, 2, 3, 4] db.close()
def amino_acids(): """Create a system database with 20 amino acids, each as a system.""" db = SystemDB(filename="file:amino_acids_db?mode=memory&cache=shared") db.read_cif_file(data_path / "aminoacids.mmcif") yield db db.close()
def test_adding_bonds(): """Test that we can add bonds""" db = SystemDB(filename="file:seamm_db?mode=memory&cache=shared") system = db.create_system(name="default") configuration = system.create_configuration() # TIP3P r0 = 0.9572 theta0 = 104.52 # H locations are ±x, 0, z x = r0 * math.sin(math.radians(theta0 / 2)) z = r0 * math.cos(math.radians(theta0 / 2)) X = [0.0, x, -x] Y = [0.0, 0.0, 0.0] Z = [0.0, z, z] atno = [8, 1, 1] name = ["O", "H1", "H2"] i_atom = [0, 0] j_atom = [1, 2] atoms = configuration.atoms atoms.add_attribute("name", "str", default="") atom_ids = atoms.append(atno=atno, x=X, y=Y, z=Z, name=name) i = [atom_ids[x] for x in i_atom] j = [atom_ids[x] for x in j_atom] bonds = configuration.bonds bond_ids = bonds.append(i=j, j=i) # flipped on purpose so code orders. assert bonds.n_bonds == 2 assert bond_ids == [1, 2] db.close()
def aa_templates(): """Create a system database with 20 amino acids, each as a template.""" db = SystemDB(filename="file:aa_templates_db?mode=memory&cache=shared") db.read_cif_file(data_path / "aminoacids.mmcif") templates = db.templates for system in db.systems: templates.create( name=system.name, category="amino acid", configuration=system.configuration.id, ) yield templates db.close()
def testdb(): """Create a database with amino acids and templates for each.""" db = SystemDB(filename="file:aa_templates_db?mode=memory&cache=shared") db.read_cif_file(data_path / "aa-variants-v1.cif") # Make the templates templates = db.templates for system in db.systems: tmp = system.name.split("_") if len(tmp) == 1: category = "amino acid" else: if tmp[1] == "LL": category = "residue" elif tmp[1] == "LEO2": category = "C-terminal residue" elif tmp[1] == "LEO2H": category = "protonated C-terminal residue" elif tmp[1] == "LFOH": category = "amino acid free neutral" elif tmp[1] == "LFZW": category = "amino acid free zwitterion" elif tmp[1] == "LSN3": category = "protonated N-terminal residue" else: raise ValueError(f"Don't recognize {tmp[1]} in {system.name}") templates.create(name=system.name, category=category, configuration=system.configuration.id) # Angiotensin II from SMILES system = db.create_system("angiotensin") configuration = system.create_configuration("SMILES") configuration.from_smiles(SMILES) # And read in system.read_cif_file(data_path / "1n9v.cif") yield db db.close()
def test_construction(): """Simplest test that we can make a SystemDB object""" db = SystemDB(filename="file:seamm_db?mode=memory&cache=shared") assert str(type(db)) == "<class 'molsystem.system_db.SystemDB'>" assert db.n_systems == 0 db.close()