class TestDBWriter: ses = create_session() def test_write_new_mol_and_new_0_conf(self): rism_toluene = RISM_3D_calculation('test/toluene') can = 'Cc1ccccc1' wr = Writer(self.ses) wr.write_rism(rism_toluene) dbi = DBInterface(self.ses) db_mol = dbi.get_molecule(can) db_can = str(db_mol.SMILES) db_conf = db_mol.find_0rmsd_conformation() pymol = pybel.readstring('mol', str(db_conf.Mol)) assert can == db_can # assert xyz == db_xyz self.ses.rollback() def test_write_new_mol_and_new_conf_and_conf_props(self): rism_toluene = RISM_3D_calculation('test/toluene') can = 'Cc1ccccc1' wr = Writer(self.ses) wr.write_rism(rism_toluene, {'Source': 'David'}) dbi = DBInterface(self.ses) db_mol = dbi.get_molecule(can) db_conf = db_mol.find_0rmsd_conformation() assert str(db_conf.Source) == 'David' self.ses.rollback() def test_update_existing_conf(self): rism_toluene = RISM_3D_calculation('test/toluene') rism_toluene_copy = RISM_3D_calculation('test/toluene_copy') can = 'Cc1ccccc1' wr = Writer(self.ses) wr.write_rism(rism_toluene) dbi = DBInterface(self.ses) db_mol = dbi.get_molecule(can) db_conf = db_mol.find_0rmsd_conformation() assert str(db_conf.Source) == 'None' wr.write_rism(rism_toluene_copy, {'Source': 'David'}) dbi = DBInterface(self.ses) db_mol = dbi.get_molecule(can) db_conf = db_mol.find_0rmsd_conformation() assert str(db_conf.Source) == 'David' self.ses.rollback() def test_write_rism_calculation(self): rism_toluene = RISM_3D_calculation('test/toluene') can = 'Cc1ccccc1' wr = Writer(self.ses) wr.write_rism(rism_toluene, {'Source': 'David'}) dbi = DBInterface(self.ses) db_mol = dbi.get_molecule(can) db_conf = db_mol.find_0rmsd_conformation() db_calc = db_conf.get_rism_calculations()[0] assert db_calc.SolvE == 1.34305025E+001 assert db_calc.Temperature == '298' self.ses.rollback()
def parse_rism_folders(base_folder): ses = create_session() dbi = DBInterface(ses) dirs = os.walk(base_folder) for p, _, filenames in dirs: dbfs = get_dbf(filenames) for dbf in dbfs: try: add_meta_f_to_db(dbf, p, dbi) except NoResultFound: print 'No results found for {}'.format(dbf) ses.commit() ses.close()
def parse_smd_folders(folders): """Accepts list (or tuple) of folders and writes smd_calculation data to db. """ ses = create_session() wr = Writer(ses) for folder in folders: try: smd = SMD_calculation(folder) wr.write_smd(smd, conf_attributes) ses.commit() print folder + ' written' except OSError, e: warnings.warn(str(e), UserWarning) except TypeError, e: warnings.warn(str(e), UserWarning)
def main(): """Should only be used to handle arguments from command line. Accepts list of folders and calls parse_rism_folders to handle the rest """ args = docopt(__doc__, version=0.01) # print args parse_args(args) if args['create_db']: check_connection() if args['add']: if args['rism']: parse_rism_folders(args['<folder>']) if args['smd']: parse_smd_folders(args['<folder>']) if args['smvle']: parse_smvle_folders(args['<folder>']) if args['exp_data']: ses = create_session() read_csv(args['<csv_file>'], ses) ses.close()
""" Created on Tue Aug 19 13:17:48 2014 @author: max """ import numpy as np import statsmodels.api as sm import solvation_database as sd from db_interface import create_session from sqlalchemy import and_ import matplotlib.pyplot as plt ses = create_session() avgd_points = open('averaged_points.txt', 'a') interp_points = open('interpoltd_points.txt', 'a') class PointBrowser: """ Delete stuff Press d to delete point Press x to delete molecule (deprecated) Close figure to continue """ def __init__(self, fig, ax, int_t, int_v, avg_t, avg_v, line, title, true_t, true_v): self.fig = fig self.line = line
class TestDBInterface: ses = create_session() def test_check_molecule_non_existing(self): SMILES='CCCCC' dbi = DBInterface(self.ses) with pytest.raises(NoResultFound) as e: dbi.get_molecule(SMILES) def test_add_molecule(self): smiles = 'CCCCCCC' mol = Molecule(SMILES=smiles, IUPACName='Heptane') dbi = DBInterface(self.ses) dbi.add_molecule(mol) data_mol = dbi.get_molecule(smiles) assert str(data_mol.SMILES) == str(mol.SMILES) def test_find_most_similair_conformation(self): molref = """ OpenBabel12071321472D 2 1 0 0 0 0 0 0 0 0999 V2000 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 M END""" mol = """ OpenBabel12071321472D 2 1 0 0 0 0 0 0 0 0999 V2000 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.7000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 M END """ can = mol_2_can(mol) dbi = DBInterface(self.ses) db_ethane = Molecule(SMILES='CC') dbi.add_molecule(db_ethane) db_mol = dbi.get_molecule(can) db_mol.add_conformation(Conformation(Mol=molref)) self.ses.add(db_mol) db_conf = db_mol.find_most_similair_conf(mol)[0] assert str(db_conf.Mol) == molref def test_add_0_rmsd_conf_existing_mol(self): coord = """ OpenBabel12071320143D 5 4 0 0 0 0 0 0 0 0999 V2000 1.0663 0.0688 -0.0295 C 0 0 0 0 0 0 0 0 0 0 0 0 2.1585 0.0688 -0.0295 H 0 0 0 0 0 0 0 0 0 0 0 0 0.7023 0.7365 0.7544 H 0 0 0 0 0 0 0 0 0 0 0 0 0.7023 -0.9440 0.1568 H 0 0 0 0 0 0 0 0 0 0 0 0 0.7023 0.4138 -0.9997 H 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 1 3 1 0 0 0 0 1 4 1 0 0 0 0 1 5 1 0 0 0 0 M END """ conf = Conformation(Mol=coord, Molecule_SMILES='C') can = mol_2_can(coord) dbi = DBInterface(self.ses) db_methane = Molecule(SMILES='C') dbi.add_molecule(db_methane) db_mol = dbi.get_molecule(can) db_mol.add_conformation(conf) self.ses.add(db_mol) db_conf = db_mol.get_conformation(coord, 0.0000001) assert db_conf == conf
def main(csv_path): ses = create_session() read_csv(csv_path, ses) ses.close()