def execute(self, args): """Run import method for every molecule in source.""" m = load_method('import', MessDB()) s = Source(MessDB()) s.setup(args.source) p = Path(MessDB()) p.setup(m.method_id) pybel.ob.obErrorLog.StopLogging() for f in s.files(): if (f.split('.')[-1] == 'sql' or f.split('.')[-1] == 'txt' or f.split('.')[-1] == 'bak' or f[-1] == '~'): continue for mol in pybel.readfile(f.split('.')[-1], os.path.join(s.source_dir, f)): decorate(mol, UnicodeDecorator) pybel.ob.obErrorLog.ClearLog() pybel.ob.obErrorLog.StartLogging() inchikey = mol.write('inchikey').rstrip() pybel.ob.obErrorLog.StopLogging() cansmi = mol.write('can').split()[0] frag_count = cansmi.count('.') + 1 for f in cansmi.split('.'): method_args = {} if (frag_count > 1): frag = pybel.readstring('can', f) decorate(frag, UnicodeDecorator) # neutralize fragments #if (frag.charge != 0): # for atom in frag.atoms: # atom.OBAtom.SetFormalCharge(0) pybel.ob.obErrorLog.ClearLog() pybel.ob.obErrorLog.StartLogging() frag_inchikey = frag.write('inchikey').rstrip() pybel.ob.obErrorLog.StopLogging() if not is_inchikey(frag_inchikey): print("'%s' is not an importable molecule.\n" % f, file=sys.stderr) continue method_args['parent'] = ('from: %s' % unicode(mol.title, 'utf-8', 'replace')) method_args['inchikey'] = frag_inchikey method_args['mol'] = frag else: if not is_inchikey(inchikey): print("'%s' is not an importable molecule.\n" % f, file=sys.stderr) continue method_args['inchikey'] = inchikey method_args['mol'] = mol method_args['source'] = s method_args['path'] = p method_args['skip_cir'] = args.skip_cir status = m.execute(method_args) print('%s: %s' % (method_args['inchikey'], status))
def check_dir_structure(self): """Check that the structure of the molecules dir is consistent.""" moldir = os.path.join(os.path.dirname(__file__), '../molecules') for l in os.listdir(moldir): lp = os.path.join(moldir, l) if not os.path.isdir(lp): print('Unexpected file in molecules dir: %s' % l) continue if not len(l) == 1: print('Unexpected dir in molecules dir: %s' % l) continue for ll in os.listdir(lp): llp = os.path.join(moldir, l, ll) if not os.path.isdir(llp): print('Unexpected file in molecules dir: %s/%s' % (l, ll)) continue if not (len(ll) == 2 and ll.isalpha()): print('Unexpected dir in molecules dir: %s/%s' % (l, ll)) continue for lll in os.listdir(llp): lllp = os.path.join(moldir, l, ll, lll) if not os.path.isdir(lllp): print('Unexpected file in molecules dir: %s/%s/%s' % (l, ll, lll)) continue if not is_inchikey(l + ll + lll, enforce_standard=True): print('Unexpected dir in molecules dir: %s/%s/%s' % (l, ll, lll)) continue self.check_molecule_dir(l + ll + lll, lllp)
def execute(self, args): """Run calculations.""" m = load_method(args.method, MessDB()) p = Path(MessDB()) p.setup(m.method_id, args.parent_path) pybel.ob.obErrorLog.StopLogging() method_args = {} method_args['path'] = p for row in args.inchikeys: method_args['inchikey'] = row.split()[0].strip() if not is_inchikey(method_args['inchikey'], enforce_standard=True): sys.exit('%s is not a valid InChIKey.' % method_args['inchikey']) status = m.execute(method_args) print('%s: %s' % (method_args['inchikey'], status))
def execute(self, args): """Run self checks.""" db = MessDB() self.c = db.cursor() self.c.execute('SELECT inchikey FROM molecule') self.db_inchikeys = set() # check that inchikeys are all valid for r in self.c: if is_inchikey(r.inchikey, enforce_standard=True): self.db_inchikeys.add(r.inchikey) else: print('%s is not a valid standard InChiKey!' % r.inchikey) self.check_dir_structure() self.check_db_structure() self.check_db_dir_inchikey_concordance() self.summary()