def index(): try: forma = request.form if forma: if 'error' in forma: return render_template('index.html') elif 'pass' in forma: data = loads(request.form['pass']) if data['pass'] == 'password': load_schema(getenv('DB_SCHEMA', 'name'), user=getenv('DB_USER', 'user'), password=getenv('DB_PASS', 'password'), host=getenv('DB_HOST', 'host'), database=getenv('DB_NAME', 'name'), port=getenv('DB_PORT', 'port')) return render_template('index.html') else: return render_template('check.html') else: return render_template('check.html') except Exception as e: return render_template('error.html', error=e), 402
def __init__(self, target, step_number=10): self.target = target with db_session: self.db = load_schema('bb', user=user, password=password, database=database, host=host) self.map = dictionary(self.db) self.action_space = list(self.map) self.observation_space = MoleculeContainer self.seed() self.state = None self.reactions_list = [] self.path = [] self.steps = 0 self.max_steps = step_number self.np_random = None self.saved_reactions = []
def load_db(neo4j, pg_schema, **kwargs): load_schema(pg_schema, **kwargs) config.DATABASE_URL = neo4j
parser = ArgumentParser(description="fill DB with data", formatter_class=ArgumentDefaultsHelpFormatter) parser.add_argument('--postgres', '-pg', type=urlparse, required=True, help='postgres connection URL [//user:pass@host:port/schema]') parser.add_argument('--neo4j', '-nj', type=str, required=True, help='neo4j connection URL') subparsers = parser.add_subparsers(title='subcommands', description='available utilities') populate = subparsers.add_parser('populate', help='load data into DB', formatter_class=ArgumentDefaultsHelpFormatter) populate.add_argument('--files', '-f', type=abspath, required=True, help='the directory with log files', default='.') populate.add_argument('--suffix', '-s', type=str, help='the log-file extension', default='.log') populate.set_defaults(func=populate_core) web = subparsers.add_parser('wui', help='run WEB UI', formatter_class=ArgumentDefaultsHelpFormatter) web.add_argument('--listening', '-ls', type=urlparse, help='listening host and port [//host:port]', default='//localhost:5000') web.add_argument('--debug', action='store_true') web.set_defaults(func=web_core) parsed = parser.parse_args() if 'func' in parsed: # setup connections pg = parsed.postgres dbs = load_schema(pg.path[1:], password=pg.password, port=pg.port, host=pg.hostname, user=pg.username) config.DATABASE_URL = parsed.neo4j # run utility parsed.func(parsed, dbs) else: parser.print_help()
from CGRdb import load_schema from CGRdb.database import Molecule from CGRdb.search.fingerprints import FingerprintMolecule from CGRtools.files import RDFwrite from CGRtools.containers import ReactionContainer import numpy as np from math import ceil from multiprocessing import Queue, Process from pony.orm import select, db_session from pickle import dump, load from itertools import islice, cycle, filterfalse from random import randint from time import time load_schema('all_patents', ) with open('pairs_from_reactant_to_product.pickle', 'rb') as f: pairs = load(f) trues = [] rank = 1000 n = 1 file = 10154 with open('True_pairs2.txt', 'w') as w: for reactant, values in pairs.items(): with db_session: reactant = Molecule[reactant].structure print('tts -->', len(values)) for product in Molecule.select(lambda x: x.id in values.keys()): stages = values[product.id] product = product.structure
from itertools import islice, chain, cycle, product, filterfalse from collections import defaultdict from math import ceil from random import shuffle, sample, choice from os import environ, listdir from pony.orm import db_session from pickle import load, dump from CGRdb import Molecule, load_schema, Reaction from pony.orm import db_session from operator import or_ from functools import reduce from CGRtools.containers import ReactionContainer from CGRtools import RDFRead db = load_schema('name', user='******', password='******', host='host', database='database') with open('starting_blocks_patents.pickle', 'rb') as f2: zinc = load(f2) with open('set_10_binar', 'rb') as f3: rules = load(f3) def worker(u, o): for chn in iter(u.get, 'STOP'): chns = [] for y in chn: rct = reduce(or_, y.reactants) pdt = reduce(or_, y.products)
from .plugins import external_scripts, external_stylesheets from CGRdb import Molecule, load_schema from CGRdbData import MoleculeProperties from pony.orm import db_session, select from collections import Counter from flask import make_response from .utilities import parse_contents MoleculeContainer._render_config['mapping'] = False color_map = [ 'rgb(0,104,55)', 'rgb(26,152,80)', 'rgb(102,189,99)', 'rgb(166,217,106)', 'rgb(217,239,139)', 'rgb(254,224,139)' ] db = load_schema('molecules', password='******', port=5432, host='localhost', user='******') def svg2html(svg): return 'data:image/svg+xml;base64,' + encodebytes( svg.encode()).decode().replace('\n', '') def brutto(mol): return ''.join(f'{a}{n}' for a, n in sorted( Counter(a.atomic_symbol for _, a in mol.atoms()).items())) dash = Dash(__name__,
# create the logging file handler fh = logging.FileHandler("new_log.log") formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) # add handler to logger object logger.addHandler(fh) logger.info("Program started") db = load_schema('all_patents', user=user, password=password, host=host, database=database, port=port) def divide_chunks(l, n): l = list(l) for i in range(0, len(l), n): yield l[i:i + n] def prepare_1(db): reactions = db.Reaction.select() # итератор реакций result = set() a = 1 with db_session:
from CGRdb import load_schema from CGRtools.containers import ReactionContainer from CGRtools.files import RDFread, SDFwrite from CGRtools.files.SDFrw import SDFread from config import * from datetime import datetime import pickle from pony.orm import db_session db = load_schema('bb', user=user, password=password, database=database, host=host) Reagents = db.Molecule def fill_mol_mol_class(): with open('group_dict_12.pickle', 'rb') as f: group_dict = pickle.load(f) with db_session: reagents = list(db.Molecule.select()) id_mol_dict = { molecule.id: molecule.structure for molecule in reagents } for mol_id, molecule in id_mol_dict.items(): id_list = [] for i, fg in group_dict.items(): if fg < molecule: with db_session: