Пример #1
0
 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))
Пример #2
0
 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))