本文整理汇总了Python中rdkit.Dbase.DbModule类的典型用法代码示例。如果您正苦于以下问题:Python DbModule类的具体用法?Python DbModule怎么用?Python DbModule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DbModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: GetColumnNamesAndTypes
def GetColumnNamesAndTypes(dBase, table, user='sysdba', password='masterkey', join='', what='*',
cn=None):
""" gets a list of columns available in a DB table along with their types
**Arguments**
- dBase: the name of the DB file to be used
- table: the name of the table to query
- user: the username for DB access
- password: the password to be used for DB access
- join: an optional join clause (omit the verb 'join')
- what: an optional clause indicating what to select
**Returns**
- a list of 2-tuples containing:
1) column name
2) column type
"""
if not cn:
cn = DbModule.connect(dBase, user, password)
c = cn.cursor()
cmd = 'select %s from %s' % (what, table)
if join:
cmd += ' join %s' % (join)
c.execute(cmd)
return GetColumnInfoFromCursor(c)
开发者ID:abradle,项目名称:rdkit,代码行数:35,代码来源:DbInfo.py
示例2: GetColumnNames
def GetColumnNames(dBase, table, user='sysdba', password='masterkey', join='', what='*', cn=None):
""" gets a list of columns available in a DB table
**Arguments**
- dBase: the name of the DB file to be used
- table: the name of the table to query
- user: the username for DB access
- password: the password to be used for DB access
- join: an optional join clause (omit the verb 'join')
- what: an optional clause indicating what to select
**Returns**
- a list of column names
"""
if not cn:
cn = DbModule.connect(dBase, user, password)
c = cn.cursor()
cmd = 'select %s from %s' % (what, table)
if join:
if join.strip().find('join') != 0:
join = 'join %s' % (join)
cmd += ' ' + join
c.execute(cmd)
c.fetchone()
desc = c.description
res = [str(x[0]) for x in desc]
return res
开发者ID:abradle,项目名称:rdkit,代码行数:35,代码来源:DbInfo.py
示例3: ProcessMol
def ProcessMol(mol,typeConversions,globalProps,nDone,nameProp='_Name',nameCol='compound_id',
redraw=False,keepHs=False,
skipProps=False,addComputedProps=False,
skipSmiles=False,
uniqNames=None,namesSeen=None):
if not mol:
raise ValueError('no molecule')
if keepHs:
Chem.SanitizeMol(mol)
try:
nm = mol.GetProp(nameProp)
except KeyError:
nm = None
if not nm:
nm = 'Mol_%d'%nDone
if uniqNames and nm in namesSeen:
logger.error('duplicate compound id (%s) encountered. second instance skipped.'%nm)
return None
namesSeen.add(nm)
row = [nm]
if not skipProps:
if addComputedProps:
nHD=Lipinski.NumHDonors(mol)
mol.SetProp('DonorCount',str(nHD))
nHA=Lipinski.NumHAcceptors(mol)
mol.SetProp('AcceptorCount',str(nHA))
nRot=Lipinski.NumRotatableBonds(mol)
mol.SetProp('RotatableBondCount',str(nRot))
MW=Descriptors.MolWt(mol)
mol.SetProp('AMW',str(MW))
logp=Crippen.MolLogP(mol)
mol.SetProp('MolLogP',str(logp))
pns = list(mol.GetPropNames())
pD={}
for pi,pn in enumerate(pns):
if pn.lower()==nameCol.lower(): continue
pv = mol.GetProp(pn).strip()
if pv.find('>')<0 and pv.find('<')<0:
colTyp = globalProps.get(pn,2)
while colTyp>0:
try:
tpi = typeConversions[colTyp][1](pv)
except:
colTyp-=1
else:
break
globalProps[pn]=colTyp
pD[pn]=typeConversions[colTyp][1](pv)
else:
pD[pn]=pv
else:
pD={}
if redraw:
AllChem.Compute2DCoords(m)
if not skipSmiles:
row.append(Chem.MolToSmiles(mol,True))
row.append(DbModule.binaryHolder(mol.ToBinary()))
row.append(pD)
return row
开发者ID:Acpharis,项目名称:rdkit,代码行数:60,代码来源:Loader_orig.py
示例4: GetDbNames
def GetDbNames(user='sysdba', password='masterkey', dirName='.', dBase='::template1', cn=None):
""" returns a list of databases that are available
**Arguments**
- user: the username for DB access
- password: the password to be used for DB access
**Returns**
- a list of db names (strings)
"""
if DbModule.getDbSql:
if not cn:
try:
cn = DbModule.connect(dBase, user, password)
except Exception:
print('Problems opening database: %s' % (dBase))
return []
c = cn.cursor()
c.execute(DbModule.getDbSql)
if RDConfig.usePgSQL:
names = ['::' + str(x[0]) for x in c.fetchall()]
else:
names = ['::' + str(x[0]) for x in c.fetchall()]
names.remove(dBase)
elif DbModule.fileWildcard:
import os.path, glob
names = glob.glob(os.path.join(dirName, DbModule.fileWildcard))
else:
names = []
return names
开发者ID:abradle,项目名称:rdkit,代码行数:34,代码来源:DbInfo.py
示例5: GetTableNames
def GetTableNames(dBase, user='sysdba', password='masterkey', includeViews=0, cn=None):
""" returns a list of tables available in a database
**Arguments**
- dBase: the name of the DB file to be used
- user: the username for DB access
- password: the password to be used for DB access
- includeViews: if this is non-null, the views in the db will
also be returned
**Returns**
- a list of table names (strings)
"""
if not cn:
try:
cn = DbModule.connect(dBase, user, password)
except Exception:
print('Problems opening database: %s' % (dBase))
return []
c = cn.cursor()
if not includeViews:
comm = DbModule.getTablesSql
else:
comm = DbModule.getTablesAndViewsSql
c.execute(comm)
names = [str(x[0]).upper() for x in c.fetchall()]
if RDConfig.usePgSQL and 'PG_LOGDIR_LS' in names:
names.remove('PG_LOGDIR_LS')
return names
开发者ID:abradle,项目名称:rdkit,代码行数:35,代码来源:DbInfo.py
示例6: GetColumns
def GetColumns(dBase,table,fieldString,user='sysdba',password='masterkey',
join='',cn=None):
""" gets a set of data from a table
**Arguments**
- dBase: database name
- table: table name
- fieldString: a string with the names of the fields to be extracted,
this should be a comma delimited list
- user and password:
- join: a join clause (omit the verb 'join')
**Returns**
- a list of the data
"""
if not cn:
cn = DbModule.connect(dBase,user,password)
c = cn.cursor()
cmd = 'select %s from %s'%(fieldString,table)
if join:
if join.strip().find('join') != 0:
join = 'join %s'%(join)
cmd +=' ' + join
c.execute(cmd)
return c.fetchall()
开发者ID:Acpharis,项目名称:rdkit,代码行数:33,代码来源:DbUtils.py
示例7: test9
def test9(self):
" substructure counts "
curs = self.conn.GetCursor()
res = curs.execute("SELECT rd_substructcount('O','OCCC(=O)O')").fetchone()
self.failUnless(res[0]==3)
res = curs.execute("SELECT rd_substructcount('N','OCCC(=O)O')").fetchone()
self.failUnless(res[0]==0)
res = curs.execute("SELECT rd_substructcount('[O,S]','SCCC(=O)O')").fetchone()
self.failUnless(res[0]==3)
res = curs.execute("SELECT rd_substructcount('[O,S]','OCCC(=O)O')").fetchone()
self.failUnless(res[0]==3)
self.failUnlessRaises(DataError,
lambda : curs.execute("SELECT rd_substructcount('QcC','c1ccccc1C');"))
curs = self.conn.GetCursor()
self.failUnlessRaises(DataError,
lambda : curs.execute("SELECT rd_substructcount('QcC','c1ccccc1C');"))
curs = self.conn.GetCursor()
self.failUnlessRaises(DataError,
lambda : curs.execute("SELECT rd_substructcount('cC','Qc1ccccc1C');"))
curs = self.conn.GetCursor()
self.failUnlessRaises(DataError,
lambda : curs.execute("SELECT rd_substructcount('nC','c1ccccn1C');"))
curs = self.conn.GetCursor()
pkl1 = DbModule.binaryHolder(Chem.MolFromSmiles('O').ToBinary())
pkl2 = DbModule.binaryHolder(Chem.MolFromSmiles('OCCC(=O)O').ToBinary())
cmd = "SELECT rd_substructcount(cast (%s as bytea),cast (%s as bytea))"
res = curs.execute(cmd,(pkl1,pkl2)).fetchone()
self.failUnless(res[0]==3)
pkl1 = DbModule.binaryHolder(Chem.MolFromSmiles('N').ToBinary())
res = curs.execute(cmd,(pkl1,pkl2)).fetchone()
self.failUnless(res[0]==0)
pkl1 = DbModule.binaryHolder(Chem.MolFromSmiles('O').ToBinary())
curs = self.conn.GetCursor()
self.failUnlessRaises(DataError,
lambda : curs.execute(cmd,('',pkl2)))
curs = self.conn.GetCursor()
self.failUnlessRaises(DataError,
lambda : curs.execute(cmd,(pkl1,'')))
curs = self.conn.GetCursor()
self.failUnlessRaises(DataError,
lambda : curs.execute(cmd,('','')))
开发者ID:aytsai,项目名称:ricebowl,代码行数:46,代码来源:wayne.py
示例8: DatabaseToText
def DatabaseToText(dBase,table,fields='*',join='',where='',
user='sysdba',password='masterkey',delim=',',cn=None):
""" Pulls the contents of a database and makes a deliminted text file from them
**Arguments**
- dBase: the name of the DB file to be used
- table: the name of the table to query
- fields: the fields to select with the SQL query
- join: the join clause of the SQL query
(e.g. 'join foo on foo.bar=base.bar')
- where: the where clause of the SQL query
(e.g. 'where foo = 2' or 'where bar > 17.6')
- user: the username for DB access
- password: the password to be used for DB access
**Returns**
- the CSV data (as text)
"""
if len(where) and where.strip().find('where')==-1:
where = 'where %s'%(where)
if len(join) and join.strip().find('join') == -1:
join = 'join %s'%(join)
sqlCommand = 'select %s from %s %s %s'%(fields,table,join,where)
if not cn:
cn = DbModule.connect(dBase,user,password)
c = cn.cursor()
c.execute(sqlCommand)
headers = []
colsToTake = []
# the description field of the cursor carries around info about the columns
# of the table
for i in range(len(c.description)):
item = c.description[i]
if item[1] not in DbInfo.sqlBinTypes:
colsToTake.append(i)
headers.append(item[0])
lines = []
lines.append(delim.join(headers))
# grab the data
results = c.fetchall()
for res in results:
d = _take(res,colsToTake)
lines.append(delim.join(map(str,d)))
return '\n'.join(lines)
开发者ID:Acpharis,项目名称:rdkit,代码行数:55,代码来源:DbUtils.py
示例9: GetCursor
def GetCursor(self):
""" returns a cursor for direct manipulation of the DB
only one cursor is available
"""
if self.cursor is not None:
return self.cursor
self.cn = DbModule.connect(self.dbName,self.user,self.password)
self.cursor = self.cn.cursor()
return self.cursor
开发者ID:ASKCOS,项目名称:rdkit,代码行数:11,代码来源:DbConnection.py
示例10: _AddDataToDb
def _AddDataToDb(dBase,table,user,password,colDefs,colTypes,data,
nullMarker=None,blockSize=100,cn=None):
""" *For Internal Use*
(drops and) creates a table and then inserts the values
"""
if not cn:
cn = DbModule.connect(dBase,user,password)
c = cn.cursor()
try:
c.execute('drop table %s'%(table))
except:
print('cannot drop table %s'%(table))
try:
sqlStr = 'create table %s (%s)'%(table,colDefs)
c.execute(sqlStr)
except:
print('create table failed: ', sqlStr)
print('here is the exception:')
import traceback
traceback.print_exc()
return
cn.commit()
c = None
block = []
entryTxt = [DbModule.placeHolder]*len(data[0])
dStr = ','.join(entryTxt)
sqlStr = 'insert into %s values (%s)'%(table,dStr)
nDone = 0
for row in data:
entries = [None]*len(row)
for col in xrange(len(row)):
if row[col] is not None and \
(nullMarker is None or row[col] != nullMarker):
if colTypes[col][0] == types.FloatType:
entries[col] = float(row[col])
elif colTypes[col][0] == types.IntType:
entries[col] = int(row[col])
else:
entries[col] = str(row[col])
else:
entries[col] = None
block.append(tuple(entries))
if len(block)>=blockSize:
nDone += _insertBlock(cn,sqlStr,block)
if not hasattr(cn,'autocommit') or not cn.autocommit:
cn.commit()
block = []
if len(block):
nDone += _insertBlock(cn,sqlStr,block)
if not hasattr(cn,'autocommit') or not cn.autocommit:
cn.commit()
开发者ID:Acpharis,项目名称:rdkit,代码行数:54,代码来源:DbUtils.py
示例11: test11
def test11(self):
" descriptors "
from rdkit.Chem import Crippen,Descriptors
curs = self.conn.GetCursor()
smi = "c1ncccc1"
m = Chem.MolFromSmiles(smi)
pkl= DbModule.binaryHolder(m.ToBinary())
ref = Crippen.MolLogP(m, includeHs=True)
res = curs.execute("SELECT rd_mollogp(%s)",(smi,)).fetchone()
v = res[0]
self.failUnlessAlmostEqual(ref,v,4)
res = curs.execute("SELECT rd_mollogp(cast (%s as bytea))",(pkl,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
res = curs.execute("SELECT rd_mollogp(rd_molpickle(%s))",(smi,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
ref = Descriptors.MolWt(m)
res = curs.execute("SELECT rd_molamw(%s)",(smi,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
res = curs.execute("SELECT rd_molamw(cast (%s as bytea))",(pkl,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
res = curs.execute("SELECT rd_molamw(rd_molpickle(%s))",(smi,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
smi = "CCOCC(C)(C)C"
m = Chem.MolFromSmiles(smi)
pkl= DbModule.binaryHolder(m.ToBinary())
ref = Crippen.MolLogP(m,includeHs=1)
res = curs.execute("SELECT rd_mollogp(%s)",(smi,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
res = curs.execute("SELECT rd_mollogp(cast (%s as bytea))",(pkl,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
res = curs.execute("SELECT rd_mollogp(rd_molpickle(%s))",(smi,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
ref = Descriptors.MolWt(m)
res = curs.execute("SELECT rd_molamw(%s)",(smi,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
res = curs.execute("SELECT rd_molamw(cast (%s as bytea))",(pkl,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
res = curs.execute("SELECT rd_molamw(rd_molpickle(%s))",(smi,))
v = res.fetchone()[0]
self.failUnlessAlmostEqual(ref,v,4)
self.failUnlessRaises(DataError,
lambda : curs.execute('select rd_mollogp(%s)',('',)))
curs = self.conn.GetCursor()
self.failUnlessRaises(DataError,
lambda : curs.execute('select rd_mollogp(%s)',('QC',)))
curs = self.conn.GetCursor()
self.failUnlessRaises(DataError,
lambda : curs.execute('select rd_mollogp(cast (%s as bytea))',('',)))
curs = self.conn.GetCursor()
self.failUnlessRaises(DataError,
lambda : curs.execute('select rd_mollogp(cast (%s as bytea))',('randomtext',)))
开发者ID:aytsai,项目名称:ricebowl,代码行数:69,代码来源:wayne.py
示例12: CreateDb
#.........这里部分代码省略.........
fpCurs.execute('create table %s (guid integer not null primary key,%s varchar not null unique,pharm2dfp blob)'%(options.pharm2DTableName,
options.molIdName))
sigFactory = BuildSigFactory(options)
if options.doGobbi2D:
fpCurs.execute('create table %s (guid integer not null primary key,%s varchar not null unique,gobbi2dfp blob)'%(options.gobbi2DTableName,
options.molIdName))
from rdkit.Chem.Pharm2D import Generate,Gobbi_Pharm2D
if options.doMorganFps :
fpConn = DbConnect(os.path.join(options.outDir,options.fpDbName))
fpCurs=fpConn.GetCursor()
try:
fpCurs.execute('drop table %s'%(options.morganFpTableName))
except:
pass
fpCurs.execute('create table %s (guid integer not null primary key,%s varchar not null unique,morganfp blob)'%(options.morganFpTableName,
options.molIdName))
if options.doDescriptors:
descrConn=DbConnect(os.path.join(options.outDir,options.descrDbName))
with open(options.descriptorCalcFilename,'r') as inTF:
buf = inTF.read().replace('\r\n', '\n').encode('utf-8')
inTF.close()
calc = cPickle.load(io.BytesIO(buf))
nms = [x for x in calc.GetDescriptorNames()]
descrCurs = descrConn.GetCursor()
descrs = ['guid integer not null primary key','%s varchar not null unique'%options.molIdName]
descrs.extend(['%s float'%x for x in nms])
try:
descrCurs.execute('drop table %s'%(options.descrTableName))
except:
pass
descrCurs.execute('create table %s (%s)'%(options.descrTableName,','.join(descrs)))
descrQuery=','.join([DbModule.placeHolder]*len(descrs))
pairRows = []
fpRows = []
layeredRows = []
descrRows = []
pharm2DRows=[]
gobbi2DRows=[]
morganRows = []
if not options.silent: logger.info('Generating fingerprints and descriptors:')
molConn = DbConnect(os.path.join(options.outDir,options.molDbName))
molCurs = molConn.GetCursor()
if not options.skipSmiles:
molCurs.execute('select guid,%s,smiles,molpkl from %s'%(options.molIdName,options.regName))
else:
molCurs.execute('select guid,%s,molpkl from %s'%(options.molIdName,options.regName))
i=0
while 1:
try:
tpl = molCurs.fetchone()
molGuid = tpl[0]
molId = tpl[1]
pkl = tpl[-1]
i+=1
except:
break
if isinstance(pkl,(bytes,str)):
mol = Chem.Mol(pkl)
else:
mol = Chem.Mol(str(pkl))
if not mol: continue
if options.doPairs:
开发者ID:BielitzLabs,项目名称:rdkit,代码行数:67,代码来源:CreateDb.py
示例13: FingerprintsFromDetails
def FingerprintsFromDetails(details, reportFreq=10):
data = None
if details.dbName and details.tableName:
from rdkit.Dbase.DbConnection import DbConnect
from rdkit.Dbase import DbInfo
from rdkit.ML.Data import DataUtils
try:
conn = DbConnect(details.dbName, details.tableName)
except Exception:
import traceback
error('Problems establishing connection to database: %s|%s\n' % (details.dbName,
details.tableName))
traceback.print_exc()
if not details.idName:
details.idName = DbInfo.GetColumnNames(details.dbName, details.tableName)[0]
dataSet = DataUtils.DBToData(details.dbName, details.tableName,
what='%s,%s' % (details.idName, details.smilesName))
idCol = 0
smiCol = 1
elif details.inFileName and details.useSmiles:
from rdkit.ML.Data import DataUtils
conn = None
if not details.idName:
details.idName = 'ID'
try:
dataSet = DataUtils.TextFileToData(details.inFileName,
onlyCols=[details.idName, details.smilesName])
except IOError:
import traceback
error('Problems reading from file %s\n' % (details.inFileName))
traceback.print_exc()
idCol = 0
smiCol = 1
elif details.inFileName and details.useSD:
conn = None
dataset = None
if not details.idName:
details.idName = 'ID'
dataSet = []
try:
s = Chem.SDMolSupplier(details.inFileName)
except Exception:
import traceback
error('Problems reading from file %s\n' % (details.inFileName))
traceback.print_exc()
else:
while 1:
try:
m = s.next()
except StopIteration:
break
if m:
dataSet.append(m)
if reportFreq > 0 and not len(dataSet) % reportFreq:
message('Read %d molecules\n' % (len(dataSet)))
if details.maxMols > 0 and len(dataSet) >= details.maxMols:
break
for i, mol in enumerate(dataSet):
if mol.HasProp(details.idName):
nm = mol.GetProp(details.idName)
else:
nm = mol.GetProp('_Name')
dataSet[i] = (nm, mol)
else:
dataSet = None
fps = None
if dataSet and not details.useSD:
data = dataSet.GetNamedData()
if not details.molPklName:
fps = apply(FingerprintsFromSmiles, (data, idCol, smiCol), details.__dict__)
else:
fps = apply(FingerprintsFromPickles, (data, idCol, smiCol), details.__dict__)
elif dataSet and details.useSD:
fps = apply(FingerprintsFromMols, (dataSet, ), details.__dict__)
if fps:
if details.outFileName:
outF = open(details.outFileName, 'wb+')
for i in range(len(fps)):
cPickle.dump(fps[i], outF)
outF.close()
dbName = details.outDbName or details.dbName
if details.outTableName and dbName:
from rdkit.Dbase.DbConnection import DbConnect
from rdkit.Dbase import DbUtils, DbModule
conn = DbConnect(dbName)
#
# We don't have a db open already, so we'll need to figure out
# the types of our columns...
#
colTypes = DbUtils.TypeFinder(data, len(data), len(data[0]))
typeStrs = DbUtils.GetTypeStrings([details.idName, details.smilesName], colTypes,
keyCol=details.idName)
cols = '%s, %s %s' % (typeStrs[0], details.fpColName, DbModule.binaryTypeName)
# FIX: we should really check to see if the table
# is already there and, if so, add the appropriate
#.........这里部分代码省略.........
开发者ID:connorcoley,项目名称:rdkit,代码行数:101,代码来源:FingerprintMols.py
示例14: GetData
def GetData(dBase,table,fieldString='*',whereString='',user='sysdba',password='masterkey',
removeDups=-1,join='',forceList=0,transform=None,randomAccess=1,extras=None,cn=None):
""" a more flexible method to get a set of data from a table
**Arguments**
- fields: a string with the names of the fields to be extracted,
this should be a comma delimited list
- where: the SQL where clause to be used with the DB query
- removeDups indicates the column which should be used to screen
out duplicates. Only the first appearance of a duplicate will
be left in the dataset.
**Returns**
- a list of the data
**Notes**
- EFF: this isn't particularly efficient
"""
if not cn:
cn = DbModule.connect(dBase,user,password)
c = cn.cursor()
cmd = 'select %s from %s'%(fieldString,table)
if join:
if join.strip().find('join') != 0:
join = 'join %s'%(join)
cmd += ' ' + join
if whereString:
if whereString.strip().find('where')!=0:
whereString = 'where %s'%(whereString)
cmd += ' ' + whereString
if forceList:
try:
if not extras:
c.execute(cmd)
else:
c.execute(cmd,extras)
except:
sys.stderr.write('the command "%s" generated errors:\n'%(cmd))
import traceback
traceback.print_exc()
return None
if transform is not None:
raise ValueError('forceList and transform arguments are not compatible')
if not randomAccess:
raise ValueError('when forceList is set, randomAccess must also be used')
data = c.fetchall()
if removeDups>0:
seen = []
for entry in data[:]:
if entry[removeDups] in seen:
data.remove(entry)
else:
seen.append(entry[removeDups])
else:
if randomAccess:
klass = RandomAccessDbResultSet
else:
klass = DbResultSet
data = klass(c,cn,cmd,removeDups=removeDups,transform=transform,extras=extras)
return data
开发者ID:Acpharis,项目名称:rdkit,代码行数:70,代码来源:DbUtils.py
示例15: CreateDb
#.........这里部分代码省略.........
)
sigFactory = BuildSigFactory(options)
if options.doGobbi2D:
fpCurs.execute(
"create table %s (guid integer not null primary key,%s varchar not null unique,gobbi2dfp blob)"
% (options.gobbi2DTableName, options.molIdName)
)
from rdkit.Chem.Pharm2D import Generate, Gobbi_Pharm2D
if options.doMorganFps:
fpConn = DbConnect(os.path.join(options.outDir, options.fpDbName))
fpCurs = fpConn.GetCursor()
try:
fpCurs.execute("drop table %s" % (options.morganFpTableName))
except:
pass
fpCurs.execute(
"create table %s (guid integer not null primary key,%s varchar not null unique,morganfp blob)"
% (options.morganFpTableName, options.molIdName)
)
if options.doDescriptors:
descrConn = DbConnect(os.path.join(options.outDir, options.descrDbName))
calc = cPickle.load(file(options.descriptorCalcFilename, "rb"))
nms = [x for x in calc.GetDescriptorNames()]
descrCurs = descrConn.GetCursor()
descrs = ["guid integer not null primary key", "%s varchar not null unique" % options.molIdName]
descrs.extend(["%s float" % x for x in nms])
try:
descrCurs.execute("drop table %s" % (options.descrTableName))
except:
pass
descrCurs.execute("create table %s (%s)" % (options.descrTableName, ",".join(descrs)))
descrQuery = ",".join([DbModule.placeHolder] * len(descrs))
pairRows = []
fpRows = []
layeredRows = []
descrRows = []
pharm2DRows = []
gobbi2DRows = []
morganRows = []
if not options.silent:
logger.info("Generating fingerprints and descriptors:")
molConn = DbConnect(os.path.join(options.outDir, options.molDbName))
molCurs = molConn.GetCursor()
if not options.skipSmiles:
molCurs.execute("select guid,%s,smiles,molpkl from %s" % (options.molIdName, options.regName))
else:
molCurs.execute("select guid,%s,molpkl from %s" % (options.molIdName, options.regName))
i = 0
while 1:
try:
tpl = molCurs.fetchone()
molGuid = tpl[0]
molId = tpl[1]
pkl = tpl[-1]
i += 1
except:
break
mol = Chem.Mol(str(pkl))
if not mol:
continue
if options.doPairs:
pairs = FingerprintUtils.BuildAtomPairFP(mol)
开发者ID:rdkit,项目名称:rdkit-orig,代码行数:67,代码来源:CreateDb.py
注:本文中的rdkit.Dbase.DbModule类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论