# from makeit.utilities.historian.chemicals import ChemHistorian # chemhistorian = ChemHistorian() # chemhistorian.load_from_file() chemhistorian = None from makeit.prioritization.precursors.scscore import SCScorePrecursorPrioritizer scscorer = SCScorePrecursorPrioritizer() scscorer.load_model(model_tag='1024bool') print('Loaded SCScorer on website') print(scscorer.get_score_from_smiles('CCCC', noprice=True)) # Solvent choices - the save file is created by the template-based forward predictor solvent_choices = [] from makeit.utilities.io.files import get_abraham_solvents_path file_path = get_abraham_solvents_path() if os.path.isfile(file_path): with open(file_path, 'rb') as fid: solvent_name_to_smiles = pickle.load(fid) solvent_choices = [{ 'smiles': v, 'name': k } for (k, v) in solvent_name_to_smiles.items()] else: db_client = MongoClient(gc.MONGO['path'], gc.MONGO['id'], connect=gc.MONGO['connect']) db = db_client[gc.SOLVENTS['database']] SOLVENT_DB = db[gc.SOLVENTS['collection']] for doc in SOLVENT_DB.find({'_id': {'$ne': 'default'}}): solvent_choices.append({
def load(self, folder="", worker_no = 0): '''Load a neural network scoring model''' if worker_no==0: MyLogger.print_and_log('Starting to load scorer...', template_nn_scorer_loc) # First load neural network if not folder: MyLogger.print_and_log( 'Cannot load neural network without the directory in which the parameters are saved. Exiting...', template_nn_scorer_loc, level=3) # Get model args ARGS_FPATH = os.path.join(folder, 'args.json') with open(ARGS_FPATH, 'r') as fid: args = json.load(fid) N_h2 = int(args['Nh2']) N_h1 = int(args['Nh1']) N_h3 = int(args['Nh3']) N_hf = int(args['Nhf']) l2v = float(args['l2']) lr = float(args['lr']) context_weight = float(args['context_weight']) enhancement_weight = float(args['enhancement_weight']) optimizer = args['optimizer'] inner_act = args['inner_act'] TARGET_YIELD = False self.model = build(F_atom=self.F_atom, F_bond=self.F_bond, N_h1=N_h1, N_h2=N_h2, N_h3=N_h3, N_hf=N_hf, l2v=l2v, inner_act=inner_act, context_weight=context_weight, enhancement_weight=enhancement_weight, TARGET_YIELD=TARGET_YIELD, absolute_score=True) WEIGHTS_FPATH = os.path.join(folder, 'weights.h5') self.model.load_weights(WEIGHTS_FPATH, by_name=True) # Now load solvent information # Try to load from file first from makeit.utilities.io.files import get_abraham_solvents_path file_path = get_abraham_solvents_path() if os.path.isfile(file_path): with open(file_path, 'rb') as fid: self.solvent_name_to_smiles = pickle.load(fid) self.solvent_smiles_to_params = pickle.load(fid) else: db_client = MongoClient(gc.MONGO['path'], gc.MONGO[ 'id'], connect=gc.MONGO['connect']) db = db_client[gc.SOLVENTS['database']] SOLVENT_DB = db[gc.SOLVENTS['collection']] for doc in SOLVENT_DB.find(): try: if doc['_id'] == 'default': self.solvent_name_to_smiles['default'] = doc['_id'] else: self.solvent_name_to_smiles[doc['name']] = doc['_id'] self.solvent_smiles_to_params[doc['_id']] = doc except KeyError: MyLogger.print_and_log('Solvent doc {} missing a name'.format( doc), template_nn_scorer_loc, level=1) with open(file_path, 'wb') as fid: pickle.dump(self.solvent_name_to_smiles, fid) pickle.dump(self.solvent_smiles_to_params, fid) if worker_no == 0: MyLogger.print_and_log('Scorer has been loaded.', template_nn_scorer_loc)