Package install :: Package MoSTBioDat :: Package DataBase :: Package ImportData :: Package Data2DB :: Module InsertMacMolTables
[hide private]
[frames] | no frames]

Source Code for Module install.MoSTBioDat.DataBase.ImportData.Data2DB.InsertMacMolTables

   1  #!/usr/bin/env python 
   2  ##################################################### 
   3  # InsertMacMolTables.py                             # 
   4  # Import table into MacroMolecule DataBase or File  # 
   5  ##################################################### 
   6   
   7  ###################################################### 
   8  # Copyright (c) 2007-2008 Andrzej Bak                # 
   9  # ARC Seibersdorf & University of Silesia            # 
  10  # Author: Andrzej Bak <Andrzej.Bak@us.edu.pl>        # 
  11  # License: GNU General Public License, version: 3    # 
  12  # URL: http://chemoinformatyka.us.edu.pl/mostbiodat/ # 
  13  # Version: 1, 06.01.2010                             # 
  14  ###################################################### 
  15   
  16  try: 
  17      import sys 
  18      import os 
  19      import pwd 
  20      import time 
  21      import anydbm 
  22      import numpy 
  23      from MoSTBioDat.DataBase.ImportData.Validator.TypeValidator import TypeValidator 
  24      from MoSTBioDat.DataBase.Query.SQLBuilder.QueryBuilder import queryBuilder 
  25      from MoSTBioDat.DataBase.Query.SQLBuilder.sqlbuilder import * 
  26      from MoSTBioDat.DataBase.Query.UserQuery.UserQuery import UserQuery 
  27      from MoSTBioDat.DataBase.ImportData.Data2DB.PDBFile import sortdictval 
  28      from MoSTBioDat.DataBase.ImportData.Data2DB.InserTables import InserTables 
  29      from MoSTBioDat.DataBase.ImportData.Data2DB.DBFile import InputDB 
  30      from MoSTBioDat.DataBase.Connect.MoSTBioDatErrors import Error 
  31   
  32  except ImportError,e: 
  33      print 'Error: %s' %e 
  34      sys.exit(1) 
  35  ############### Insert MacroMolecule Tables class ############################ 
36 -class InsertMacMolTables(InserTables):
37 - def __init__(self):
38 """ 39 Methods for inserting data from SDF file into MSDSD database tables 40 INPUT: 41 OUTPUT: 42 class object 43 """ 44 InserTables.__init__(self)
45
46 - def Entry(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,headict={},**kwarg):
47 """ 48 Entry table import 49 INPUT: 50 logdebug - log debug in log file 51 tabcolvalidict - dict, table column/value dictionary, default empty 52 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 53 headict - dict, pdb header dictionary, default empty 54 **kwarg - ID, IDlist, IDict 55 OUTPUT: 56 ID - id table value 57 """ 58 ############################################################################### 59 tablename='Entry' 60 if lowercasetablenames: 61 tablename=tablename.lower() 62 tabcol=['Id','PDBCode','PDBParentId']#column names 63 ################################################################################ 64 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 65 print 'Error, %s: Incorrect table description!'%tablename 66 self.log.error('%s: Incorrect table description',tablename) 67 sys.exit(1) 68 if not kwarg.has_key('anyflag'): 69 kwarg.setdefault('anyflag',False) 70 if not kwarg.has_key('conflag'): 71 kwarg.setdefault('conflag',False) 72 73 pdbcode=tabcolvaldict.get('PDBCode',None)#pdb code given by user 74 if not pdbcode: 75 header=headict.get('HEADER',None)#get header 76 if header: 77 header=header[0] 78 pdbcode=header[52:56]+6*' '#get pdb code from header and add 6 spaces 79 else: 80 print 'Error: PDB entry code not available!' 81 self.log.debug('%s: PDB code not available',tablename) 82 sys.exit(1) 83 if not isinstance(pdbcode,str): 84 print 'Error %s: PDB entry code must be in string format!' %tablename 85 self.log.error('%s: PDB entry code must be in string format',tablename) 86 sys.exit(1) 87 indict={}#input list 88 if pdbcode.rstrip(' ').isalnum() and len(pdbcode)==10: 89 indict[tabcol[1]]=pdbcode 90 else: 91 print 'Error: Incorrect 10 letter PDB entry code format! 10 alphanumeric entry code needed!' 92 self.log.debug('%s: Incorrect 10 letter PDB entry code format',tablename) 93 sys.exit(1) 94 95 pdbparentid=tabcolvaldict.get('PDBParentId',None) 96 if pdbparentid: 97 if not isinstance(pdbparentid,str): 98 print 'Error %s: ParentPDB entry code must be in string format!' %tablename 99 self.log.error('%s: ParentPDB entry code must be in string format',tablename) 100 sys.exit(1) 101 if not pdbparentid.rstrip(' ').isalnum(): 102 print 'Error %s: Wrong PDBParent code specification!' %tablename 103 self.log.debug('%s: Wrong PDBParent code specification',tablename) 104 sys.exit(1) 105 106 select='Select([table.'+ tablename +'.'+tabcol[0]+'], where=OR(table.'+tablename+'.'+tabcol[1]+'==pdbcode))' 107 sql=queryBuilder(eval(select))#build query 108 result=self.executeQuery(sql)#execute query 109 if result:#if record exists in table 110 if kwarg['conflag']: 111 ID=[]##get ID 112 for resitem in result:#iterate result dictionary 113 ID.append(resitem[tabcol[0]])#output ID list 114 return ID 115 print 'Error, %s: Duplicated PDBCode, please change your 10 letter PDB code!' %tablename 116 self.log.error('%s: Duplicated PDBCode, please change your 10 letter PDB code!',tablename) 117 sys.exit(1) 118 119 if kwarg['conflag']: 120 print 'Error %s: PDB code not available in database!' %tablename 121 self.log.error('%s: PDB code not available in database.' %tablename) 122 sys.exit(1) 123 124 if pdbparentid: 125 select='Select([table.'+ tablename +'.'+tabcol[0]+'], where=OR(table.'+tablename+'.'+tabcol[1]+'==pdbparentid))' 126 sql=queryBuilder(eval(select))#build query 127 result=self.executeQuery(sql)#execute query 128 if result:#if record exists in table 129 parID=[]##get ID 130 for resitem in result:#iterate result dictionary 131 parID.append(resitem[tabcol[0]])#output ID list 132 if parID: 133 indict[tabcol[2]]=parID 134 else: 135 print 'Error %s: PDBParent code not available in database!' %tablename 136 self.log.error('%s: PDBParent code not available in database.' %tablename) 137 sys.exit(1) 138 139 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 140 inskey,insval=insPrep(**inrow)#preparation for insertion to table 141 if kwarg['anyflag']:#remove items with at least False value 142 insval=filter(checkitem,insval) 143 if not all([checkitem(val) for val in insval]):#check all values are True 144 return 0 145 if not insval:##input list is empty 146 return 0 147 148 return self.insertrecord(tablename,inskey,insval,logdebug)
149 150 getEntry=Entry 151
152 - def Model(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
153 """ 154 Model table import 155 INPUT: 156 logdebug - log debug in log file 157 tabcolvalidict - dict, table column/value dictionary, default empty 158 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 159 **kwarg - ID, IDlist, IDict 160 OUTPUT: 161 ID - id table value 162 """ 163 ############################################################################### 164 tablename='Model' 165 if lowercasetablenames: 166 tablename=tablename.lower() 167 tabcol=['Id','ModId','EntryIdFk']#column names 168 ################################################################################ 169 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 170 print 'Error, %s: Incorrect table description!'%tablename 171 self.log.error('%s: Incorrect table description',tablename) 172 sys.exit(1) 173 if not kwarg.has_key('anyflag'): 174 kwarg.setdefault('anyflag',False) 175 176 indict={}#input list 177 ID=kwarg.get('ID',None) 178 if ID:## ID must be list of length=1 179 if not isinstance(ID,list) or len(ID)!=1: 180 print 'Error, %s: Incorrect ID specification!' %tablename 181 if logdebug: 182 self.log.debug('%s: Incorrect ID specification',tablename) 183 return 0 184 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 185 indict[tabcol[2]]=str(ID[0])#set Entry foreign key 186 187 modelist=kwarg.get('modelist',None)#get model list 188 if not modelist:#no model list 189 print 'Error %s: Model list not available!' %tablename 190 if logdebug: 191 self.log.debug('%s: Model list not available',tablename) 192 sys.exit(1) 193 194 indict[tabcol[1]]=modelist#set model list 195 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 196 inskey,insval=insPrep(**inrow)#preparation for insertion to table 197 if kwarg['anyflag']:#remove items with at least False value 198 insval=filter(checkitem,insval) 199 if not all([checkitem(val) for val in insval]):#check all values are True 200 return 0 201 if not insval:##input list is empty 202 return 0 203 204 IDlist=self.insertrecord(tablename,inskey,insval,logdebug) 205 IDict={} 206 i=0 207 208 for insitem in insval:#iterate items in insertion values list 209 insrecord=dict(zip(inskey,insitem))#insert record 210 IDict[insrecord[tabcol[1]]]=[str(IDlist[i]) ] 211 i+=1 212 213 return IDict
214
215 - def getModel(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
216 """ 217 Get Model dictionary for specified Entry 218 INPUT: 219 logdebug - log debug in log file 220 tabcolvalidict - dict, table column/value dictionary, default empty 221 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 222 **kwarg - ID, IDlist, IDict 223 OUTPUT: 224 IDict - dict, model ID dictionary 225 """ 226 ############################################################################### 227 tablename='Model' 228 if lowercasetablenames: 229 tablename=tablename.lower() 230 tabcol=['Id','ModId','EntryIdFk']#column names 231 ################################################################################ 232 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 233 print 'Error, %s: Incorrect table description!'%tablename 234 self.log.error('%s: Incorrect table description',tablename) 235 sys.exit(1) 236 ID=kwarg.get('ID',None) 237 if ID:## ID must be list of length=1 238 if not isinstance(ID,list) or len(ID)!=1: 239 print 'Error, %s: Incorrect ID specification!' %tablename 240 if logdebug: 241 self.log.debug('%s: Incorrect ID specification',tablename) 242 return 0 243 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 244 EntryIdFk=str(ID[0])#set Entry foreign key 245 else: 246 print 'Error: Specify ID' 247 self.log.error('Specify ID') 248 return 0 249 250 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+'], where=OR(table.'+tablename+'.'+tabcol[2]+'==EntryIdFk))' 251 sql=queryBuilder(eval(select))#build query 252 result=self.executeQuery(sql)#execute query 253 if result: 254 IDict=dict([(resultval[tabcol[1]],resultval[tabcol[0]]) for resultval in result]) 255 return IDict 256 else: 257 return 0
258
259 - def AltLoc(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
260 """ 261 AltLoc table import 262 INPUT: 263 logdebug - log debug in log file 264 tabcolvalidict - dict, table column/value dictionary, default empty 265 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 266 **kwarg - ID, IDlist, IDict 267 OUTPUT: 268 ID - id table value 269 """ 270 ############################################################################### 271 tablename='AltLoc' 272 if lowercasetablenames: 273 tablename=tablename.lower() 274 tabcol=['Id','AltName','EntryIdFk']#column names 275 ################################################################################ 276 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 277 print 'Error, %s: Incorrect table description!'%tablename 278 self.log.error('%s: Incorrect table description',tablename) 279 sys.exit(1) 280 if not kwarg.has_key('anyflag'): 281 kwarg.setdefault('anyflag',False) 282 283 indict={}#input list 284 ID=kwarg.get('ID',None) 285 if ID:## ID must be list of length=1 286 if not isinstance(ID,list) or len(ID)!=1: 287 print 'Error, %s: Incorrect ID specification!' %tablename 288 if logdebug: 289 self.log.debug('%s: Incorrect ID specification',tablename) 290 return 0 291 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 292 indict[tabcol[2]]=str(ID[0])#set Entry foreign key 293 294 altloclist=kwarg.get('altloclist',None)#get model list 295 if altloclist is None:#no model list 296 print 'Warning %s: AltLoc list not available!' %tablename 297 if logdebug: 298 self.log.debug('%s: AltLoc list not available',tablename) 299 sys.exit(1) 300 301 if not altloclist:#empty list 302 return {} 303 indict[tabcol[1]]=altloclist#set alternate location list 304 305 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 306 inskey,insval=insPrep(**inrow)#preparation for insertion to table 307 if kwarg['anyflag']:#remove items with at least False value 308 insval=filter(checkitem,insval) 309 if not all([checkitem(val) for val in insval]):#check all values are True 310 return 0 311 if not insval:##input list is empty 312 return 0 313 314 IDlist=self.insertrecord(tablename,inskey,insval,logdebug) 315 IDict={} 316 i=0 317 318 for insitem in insval:#iterate items in insertion values list 319 insrecord=dict(zip(inskey,insitem))#insert record 320 IDict[insrecord[tabcol[1]]]=[str(IDlist[i]) ] 321 i+=1 322 323 return IDict
324
325 - def getAltLoc(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
326 """ 327 Get AltLoc dictionary for specified Entry 328 INPUT: 329 logdebug - log debug in log file 330 tabcolvalidict - dict, table column/value dictionary, default empty 331 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 332 **kwarg - ID, IDlist, IDict 333 OUTPUT: 334 IDict - dict, model ID dictionary 335 """ 336 ############################################################################### 337 tablename='AltLoc' 338 if lowercasetablenames: 339 tablename=tablename.lower() 340 tabcol=['Id','AltName','EntryIdFk']#column names 341 ################################################################################ 342 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 343 print 'Error, %s: Incorrect table description!'%tablename 344 self.log.error('%s: Incorrect table description',tablename) 345 sys.exit(1) 346 ID=kwarg.get('ID',None) 347 if ID:## ID must be list of length=1 348 if not isinstance(ID,list) or len(ID)!=1: 349 print 'Error, %s: Incorrect ID specification!' %tablename 350 if logdebug: 351 self.log.debug('%s: Incorrect ID specification',tablename) 352 return 0 353 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 354 EntryIdFk=str(ID[0])#set Entry foreign key 355 else: 356 print 'Error: Specify ID' 357 self.log.error('Specify ID') 358 return 0 359 360 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+'], where=OR(table.'+tablename+'.'+tabcol[2]+'==EntryIdFk))' 361 sql=queryBuilder(eval(select))#build query 362 result=self.executeQuery(sql)#execute query 363 if result: 364 IDict=dict([(resultval[tabcol[1]],[str(resultval[tabcol[0]])]) for resultval in result]) 365 return IDict 366 else: 367 return 0
368
369 - def Chain(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
370 """ 371 Chain table import 372 INPUT: 373 logdebug - log debug in log file 374 tabcolvalidict - dict, table column/value dictionary, default empty 375 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 376 **kwarg - ID, IDlist, IDict 377 OUTPUT: 378 ID - id table value 379 """ 380 ############################################################################### 381 tablename='Chain' 382 if lowercasetablenames: 383 tablename=tablename.lower() 384 tabcol=['Id','ChainCode','EntryIdFk']#column names 385 ################################################################################ 386 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 387 print 'Error, %s: Incorrect table description!'%tablename 388 self.log.error('%s: Incorrect table description',tablename) 389 sys.exit(1) 390 if not kwarg.has_key('anyflag'): 391 kwarg.setdefault('anyflag',False) 392 393 indict={}#input list 394 ID=kwarg.get('ID',None) 395 if ID:## ID must be list of length=1 396 if not isinstance(ID,list) or len(ID)!=1: 397 print 'Error, %s: Incorrect ID specification!' %tablename 398 if logdebug: 399 self.log.debug('%s: Incorrect ID specification',tablename) 400 return 0 401 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 402 indict[tabcol[2]]=str(ID[0])#set Entry foreign key 403 404 chainlist=kwarg.get('chainlist',None)#get chain list 405 if chainlist is None:#no chain list 406 print 'Warning %s: Chain list not available!' %tablename 407 if logdebug: 408 self.log.debug('%s: Chain list not available',tablename) 409 sys.exit(1) 410 if not chainlist:#empty list 411 return {} 412 indict[tabcol[1]]=chainlist#set chain list 413 414 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 415 inskey,insval=insPrep(**inrow)#preparation for insertion to table 416 if kwarg['anyflag']:#remove items with at least False value 417 insval=filter(checkitem,insval) 418 if not all([checkitem(val) for val in insval]):#check all values are True 419 return 0 420 if not insval:##input list is empty 421 return 0 422 423 IDlist=self.insertrecord(tablename,inskey,insval,logdebug) 424 IDict={} 425 i=0 426 427 for insitem in insval:#iterate items in insertion values list 428 insrecord=dict(zip(inskey,insitem))#insert record 429 IDict[insrecord[tabcol[1]]]=[str(IDlist[i]) ] 430 i+=1 431 432 return IDict
433
434 - def getChain(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
435 """ 436 Get Chain dictionary for specified Entry 437 INPUT: 438 logdebug - log debug in log file 439 tabcolvalidict - dict, table column/value dictionary, default empty 440 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 441 **kwarg - ID, IDlist, IDict 442 OUTPUT: 443 IDict - dict, model ID dictionary 444 """ 445 ############################################################################### 446 tablename='Chain' 447 if lowercasetablenames: 448 tablename=tablename.lower() 449 tabcol=['Id','ChainCode','EntryIdFk']#column names 450 ################################################################################ 451 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 452 print 'Error, %s: Incorrect table description!'%tablename 453 self.log.error('%s: Incorrect table description',tablename) 454 sys.exit(1) 455 ID=kwarg.get('ID',None) 456 if ID:## ID must be list of length=1 457 if not isinstance(ID,list) or len(ID)!=1: 458 print 'Error, %s: Incorrect ID specification!' %tablename 459 if logdebug: 460 self.log.debug('%s: Incorrect ID specification',tablename) 461 return 0 462 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 463 EntryIdFk=str(ID[0])#set Entry foreign key 464 else: 465 print 'Error: Specify ID' 466 self.log.error('Specify ID') 467 return 0 468 469 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+'], where=OR(table.'+tablename+'.'+tabcol[2]+'==EntryIdFk))' 470 sql=queryBuilder(eval(select))#build query 471 result=self.executeQuery(sql)#execute query 472 if result: 473 IDict=dict([(resultval[tabcol[1]],[str(resultval[tabcol[0]])]) for resultval in result]) 474 return IDict 475 else: 476 return 0
477
478 - def getChainReSeq(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
479 """ 480 get ChainReSeq table data for specified chain 481 INPUT: 482 logdebug - log debug in log file 483 tabcolvalidict - dict, table column/value dictionary, default empty 484 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 485 moldict -dict, molecule description dictionary 486 **kwarg - ID, IDlist, IDict 487 OUTPUT: 488 ID - id table value 489 """ 490 ############################################################################### 491 tablename='ChainReSeq' 492 if lowercasetablenames: 493 tablename=tablename.lower() 494 tabcol=['Id','ResName','ChainIdFk']#column names 495 ################################################################################ 496 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 497 print 'Error, %s: Incorrect table description!'%tablename 498 self.log.error('%s: Incorrect table description',tablename) 499 sys.exit(1) 500 if not kwarg.has_key('anyflag'): 501 kwarg.setdefault('anyflag',False) 502 503 indict={}#input list 504 ID=kwarg.get('ID',None) 505 if ID:## ID must be list of length=1 506 if not isinstance(ID,list) or len(ID)!=1: 507 print 'Error, %s: Incorrect ID specification!' %tablename 508 if logdebug: 509 self.log.debug('%s: Incorrect ID specification',tablename) 510 return 0 511 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 512 indict[tabcol[2]]=str(ID[0])#set Chain foreign key 513 514 IDlist=kwarg.get('IDlist',None) 515 if IDlist:## must be list 516 if not isinstance(IDlist,list): 517 print 'Error, %s: Incorrect IDlist specification!' %tablename 518 if logdebug: 519 self.log.debug('%s: Incorrect IDlist specification',tablename) 520 return 0 521 522 IDict=kwarg.get('IDict',None) 523 if IDict:## must be dictionary 524 if not isinstance(IDict,dict): 525 print 'Error, %s: Incorrect IDict specification!' %tablename 526 if logdebug: 527 self.log.debug('%s: Incorrect IDict specification',tablename) 528 return 0 529 ChainIdFkDict=IDict 530 if not ChainIdFkDict: 531 print 'Error, %s: Chain foreign key not available!' %tablename 532 if logdebug: 533 self.log.debug('%s: Chain foreign key not available',tablename) 534 return 0 535 outIDict={} 536 for chainidfk, chainid in ChainIdFkDict.iteritems(): 537 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+'], where=OR(table.'+tablename+'.'+tabcol[2]+'==chainidfk))' 538 sql=queryBuilder(eval(select))#build query 539 result=self.executeQuery(sql)#execute query 540 if result: 541 IDict=dict([(resultval[tabcol[0]],resultval[tabcol[1]]) for resultval in result]) 542 IDictkey=sorted(IDict.keys())#sort Id 543 ID={} 544 ID[chainid]=[IDict[idkey] for idkey in IDictkey] 545 outIDict.update(ID) 546 return outIDict
547
548 - def ChainReSeq(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
549 """ 550 ChainReseq table import 551 INPUT: 552 logdebug - log debug in log file 553 tabcolvalidict - dict, table column/value dictionary, default empty 554 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 555 moldict -dict, molecule description dictionary 556 **kwarg - ID, IDlist, IDict 557 OUTPUT: 558 ID - id table value 559 """ 560 ############################################################################### 561 tablename='ChainReSeq' 562 if lowercasetablenames: 563 tablename=tablename.lower() 564 tabcol=['Id','ResName','ChainIdFk']#column names 565 ################################################################################ 566 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 567 print 'Error, %s: Incorrect table description!'%tablename 568 self.log.error('%s: Incorrect table description',tablename) 569 sys.exit(1) 570 if not kwarg.has_key('anyflag'): 571 kwarg.setdefault('anyflag',False) 572 573 indict={}#input list 574 ID=kwarg.get('ID',None) 575 if ID:## ID must be list of length=1 576 if not isinstance(ID,list) or len(ID)!=1: 577 print 'Error, %s: Incorrect ID specification!' %tablename 578 if logdebug: 579 self.log.debug('%s: Incorrect ID specification',tablename) 580 return 0 581 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 582 indict[tabcol[2]]=str(ID[0])#set Chain foreign key 583 584 IDlist=kwarg.get('IDlist',None) 585 if IDlist:## must be list 586 if not isinstance(IDlist,list): 587 print 'Error, %s: Incorrect IDlist specification!' %tablename 588 if logdebug: 589 self.log.debug('%s: Incorrect IDlist specification',tablename) 590 return 0 591 592 IDict=kwarg.get('IDict',None) 593 if IDict:## must be dictionary 594 if not isinstance(IDict,dict): 595 print 'Error, %s: Incorrect IDict specification!' %tablename 596 if logdebug: 597 self.log.debug('%s: Incorrect IDict specification',tablename) 598 return 0 599 600 seqresdict=kwarg.get('seqresdict',None) 601 if not seqresdict: 602 print 'Warning %s: Sequence residue dictionary not available!' %tablename 603 if logdebug: 604 self.log.debug('%s: Sequence residue dictionary not available',tablename) 605 sys.exit(1) 606 607 outIDict={} 608 609 for chainame, chainreslist in seqresdict.iteritems(): 610 if IDict.has_key(chainame): 611 indict[tabcol[2]]=str(IDict[chainame][0]) 612 indict[tabcol[1]]=chainreslist 613 else: 614 print 'Warning: Chain foreign key for %s not available!' %chainame 615 if logdebug: 616 self.log.debug('%s: Chain foreign key for %s not available',tablename, chainame) 617 continue 618 619 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 620 inskey,insval=insPrep(**inrow)#preparation for insertion to table 621 if kwarg['anyflag']:#remove items with at least False value 622 insval=filter(checkitem,insval) 623 if not all([checkitem(val) for val in insval]):#check all values are True 624 return 0 625 if not insval:##input list is empty 626 return 0 627 IDlist=self.insertrecord(tablename,inskey,insval,logdebug) 628 outIDict[chainame]=IDlist 629 630 return outIDict
631
632 - def Molecule(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
633 """ 634 Molecule table import 635 INPUT: 636 logdebug - log debug in log file 637 tabcolvalidict - dict, table column/value dictionary, default empty 638 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 639 moldict -dict, molecule description dictionary 640 **kwarg - ID, IDlist, IDict 641 OUTPUT: 642 ID - id table value 643 """ 644 ############################################################################### 645 tablename='Molecule' 646 if lowercasetablenames: 647 tablename=tablename.lower() 648 tabcol=['Id','MolType','MolId','MolCode','MolName','MolFormula','MolWeight','ChemCompIdFk','EntryIdFk']#column names 649 ################################################################################ 650 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 651 print 'Error, %s: Incorrect table description!'%tablename 652 self.log.error('%s: Incorrect table description',tablename) 653 sys.exit(1) 654 if not kwarg.has_key('anyflag'): 655 kwarg.setdefault('anyflag',False) 656 657 indict={}#input list 658 ID=kwarg.get('ID',None) 659 if ID:## ID must be list of length=1 660 if not isinstance(ID,list) or len(ID)!=1: 661 print 'Error, %s: Incorrect ID specification!' %tablename 662 if logdebug: 663 self.log.debug('%s: Incorrect ID specification',tablename) 664 return 0 665 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 666 indict[tabcol[8]]=str(ID[0])#set Entry foreign key 667 668 IDict=kwarg.get('IDict',None) 669 if IDict:## must be dictionary 670 if not isinstance(IDict,dict): 671 print 'Error, %s: Incorrect IDict specification!' %tablename 672 if logdebug: 673 self.log.debug('%s: Incorrect IDict specification',tablename) 674 return 0 675 676 PropDefID=IDict.get('PropDefIDict',None) 677 678 moldict=kwarg.get('moldict',None)#get molecule dictionary 679 if not moldict:#no molecule dictionary 680 print 'Warning %s: Molecule dictionary not available!' %tablename 681 if logdebug: 682 self.log.debug('%s: Molecule dictionary not available',tablename) 683 sys.exit(1) 684 685 for colname in tabcol: 686 if moldict.has_key(colname): 687 indict[colname]=moldict[colname] 688 689 ProtStatID=0 690 AtomsID=0 691 if self.ligandb: 692 moltype=moldict.get('MolType',None) 693 if not moltype: 694 print 'Error %s: Molecule type not available!'%tablename 695 if logdebug: 696 self.log.debug('%s: Molecule type not available!',tablename) 697 sys.exit(1) 698 699 if moltype!='P': 700 molisosmi=moldict.get('IsoSmi',None) 701 if not molisosmi: 702 print 'Error %s: Molecule isomeric SMILE not available!' %tablename 703 if logdebug: 704 self.log.debug('%s: Molecule isomeric SMILE not available',tablename) 705 sys.exit(1) 706 macdbname=self.kwargs['db']#get macromolecule database name 707 self.kwargs['db']=self.ligandb#set db to ligand database 708 ### check if isomeric smile exists in ProtStat table ### 709 ChemCompIdFk=self.getProtStat(logdebug=logdebug,tabcolvaldict={'IsoSmi':molisosmi},lowercasetablenames=lowercasetablenames,iso=False) 710 711 if ChemCompIdFk: 712 ChemCompID=ChemCompIdFk 713 else: 714 ### import to Ligand.ChemComp table ### 715 ChemCompID=self.UserChemComp(logdebug=logdebug,lowercasetablenames=lowercasetablenames,tabcolvaldict={'IsoSmi':molisosmi},iso=False) 716 if not ChemCompID: 717 print 'Error %s: Incorrect ChemComp foreign key for %s!' %(tablename, molisosmi) 718 if logdebug: 719 self.log.debug('%s: Incorrect ChemComp foreign key for %s',tablename,molisosmi) 720 sys.exit(1) 721 722 indictobj={} 723 indictobj['property']={tabcol[8]:str(ID[0])} 724 indictobj['isosmi']=molisosmi 725 bonds=moldict.get('MolBonds',None) 726 if not bonds: 727 print 'Error %s: Molecule bonds not available for %s!' %(tablename,molisosmi) 728 if logdebug: 729 self.log.debug('%s: Molecule bonds not available for %s',tablename,molisosmi) 730 sys.exit(1) 731 indictobj.update(bonds) 732 symq=moldict.get('MolSymQ',None) 733 if not symq: 734 print 'Error %s: Molecule symbol and charge not available for %s!'%(tablename,molisosmi) 735 if logdebug: 736 self.log.debug('%s: Molecule symbol and charge not available for %s',tablename,molisosmi) 737 indictobj.update(symq) 738 indictobj['filename']=molisosmi 739 dictobj=InputDB(**indictobj) 740 #import to PropChemCompInt table 741 proptablename='PropChemCompInt'#tablename 742 proptabcol= ['Id', 'PropVal', 'PropDefIdFk', 'ChemCompIdFk']#table columname list 743 propmapdict=['autoincrement', 'property{\'EntryIdFk\'}','IDict', 'ID']# mapping dictionary object attributes 744 PropChemCompIDInt=self.Prop2Tab(proptablename,proptabcol,propmapdict,dictobj,anyflag=kwarg['anyflag'],logdebug=logdebug,lowercasetablenames=lowercasetablenames,IDcheck=False,IDict=PropDefID,ID=ChemCompID) 745 746 ###import to Ligand.ProtStat table ### 747 ProtStatID=self.ProtStat(dictobj=dictobj,logdebug=logdebug,lowercasetablenames=lowercasetablenames,ID=ChemCompID) 748 if not ProtStatID: 749 print 'Error %s: Incorrect ProtStat foreign key for %s!' %(tablename, molisosmi) 750 if logdebug: 751 self.log.debug('%s: Incorrect ProtStat foreign key for %s',tablename,molisosmi) 752 sys.exit(1) 753 ###import to Ligand.ConnTab table ### 754 ConnTabID=self.ConnTab(dictobj,logdebug=logdebug,lowercasetablenames=lowercasetablenames,ID=ProtStatID) 755 ###import to Ligand.Atoms table ### 756 AtomsID=self.Atoms(dictobj,logdebug=logdebug,lowercasetablenames=lowercasetablenames,ID=ProtStatID) 757 if not AtomsID: 758 print 'Error %s: Incorrect Atoms foreign key for %s!' %(tablename, molisosmi) 759 if logdebug: 760 self.log.debug('%s: Incorrect Atoms foreign key for %s',tablename,molisosmi) 761 sys.exit(1) 762 763 self.kwargs['db']=macdbname# set db to macromolecule database 764 if ChemCompID and ProtStatID and AtomsID: 765 indict[tabcol[7]]=ChemCompID#set ligand.chemcomp foreign key 766 767 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 768 inskey,insval=insPrep(**inrow)#preparation for insertion to table 769 if kwarg['anyflag']:#remove items with at least False value 770 insval=filter(checkitem,insval) 771 if not all([checkitem(val) for val in insval]):#check all values are True 772 return 0 773 if not insval:##input list is empty 774 return 0 775 776 return self.insertrecord(tablename,inskey,insval,logdebug),ProtStatID, AtomsID
777
778 - def getMolecule(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
779 """ 780 Get Molecule dictionary for specified Entry 781 INPUT: 782 logdebug - log debug in log file 783 tabcolvalidict - dict, table column/value dictionary, default empty 784 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 785 moldict -dict, molecule description dictionary 786 **kwarg - ID, IDlist, IDict 787 OUTPUT: 788 IDict - dict, model ID dictionary 789 """ 790 ############################################################################### 791 tablename='Molecule' 792 if lowercasetablenames: 793 tablename=tablename.lower() 794 tabcol=['Id','MolType','MolId','MolCode','MolName','MolFormula','MolWeight','ChemCompIdFk','EntryIdFk']#column names 795 ################################################################################ 796 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 797 print 'Error, %s: Incorrect table description!'%tablename 798 self.log.error('%s: Incorrect table description',tablename) 799 sys.exit(1) 800 ID=kwarg.get('ID',None) 801 if ID:## ID must be list of length=1 802 if not isinstance(ID,list) or len(ID)!=1: 803 print 'Error, %s: Incorrect ID specification!' %tablename 804 if logdebug: 805 self.log.debug('%s: Incorrect ID specification',tablename) 806 return 0 807 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 808 EntryIdFk=str(ID[0])#set Entry foreign key 809 else: 810 print 'Error: Specify ID' 811 self.log.error('Specify ID') 812 return 0 813 814 IDict=kwarg.get('IDict',None) 815 if IDict:## must be dictionary 816 if not isinstance(IDict,dict): 817 print 'Error, %s: Incorrect IDict specification!' %tablename 818 if logdebug: 819 self.log.debug('%s: Incorrect IDict specification',tablename) 820 return 0 821 822 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[7] +',table.'+ tablename +'.'+tabcol[3]+'], where=OR(table.'+tablename+'.'+tabcol[8]+'==EntryIdFk))' 823 sql=queryBuilder(eval(select))#build query 824 result=self.executeQuery(sql)#execute query 825 if result: 826 IDictout=dict([(resultval[tabcol[0]],resultval) for resultval in result]) 827 ProtStatIDict={} 828 for IDkey,IDval in IDictout.iteritems(): 829 IDkey=[IDkey]#input must be list 830 831 if self.ligandb: 832 moltype=IDval.get('MolType',None)#get molecule type 833 if not moltype: 834 print 'Error %s: Molecule type not available!'%tablename 835 if logdebug: 836 self.log.debug('%s: Molecule type not available!',tablename) 837 sys.exit(1) 838 if moltype!='P': 839 chemcompidfk=IDval.get('ChemCompIdFk',None)#get ligand.chemcomp foreign key 840 if chemcompidfk:#if not null 841 chemcompidfk=[chemcompidfk] 842 macdbname=self.kwargs['db']#get macromolecule database name 843 try: 844 self.kwargs['db']=self.ligandb#set db to ligand database 845 protstatid=self.getProtStatonIdFk(logdebug=logdebug,tabcolvaldict={'ChemCompIdFk':chemcompidfk},lowercasetablenames=lowercasetablenames) 846 if protstatid: 847 for protstatval in protstatid.values(): 848 atomsid=self.getAtomsonIdFk(logdebug=logdebug,tabcolvaldict={'ProtStatIdFk':protstatval},lowercasetablenames=lowercasetablenames) 849 if atomsid: 850 protstatval.append(atomsid) 851 ProtStatIDict.update(protstatid) 852 self.kwargs['db']=macdbname# set db to macromolecule database 853 except Error,e: 854 print 'Error: %s'%e 855 sys.exit(1) 856 857 ChainMolIDict=self.getChainMol(logdebug=logdebug,tabcolvaldict=tabcolvaldict,lowercasetablenames=lowercasetablenames,ID=IDkey) 858 if ChainMolIDict: 859 for ChainMolkey in ChainMolIDict.iterkeys(): 860 if IDictout.has_key(ChainMolkey): 861 templist=[] 862 for chainidfkitem in ChainMolIDict[ChainMolkey]['ChainIdFk']: 863 if IDict.has_key(chainidfkitem): 864 templist.append(IDict[chainidfkitem]) 865 tempdict={'MolChain':templist} 866 IDictout[ChainMolkey].update(tempdict) 867 868 return IDictout,ProtStatIDict 869 else:# no result 870 return 0
871
872 - def ChainMol(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
873 """ 874 Chain table import 875 INPUT: 876 logdebug - log debug in log file 877 tabcolvalidict - dict, table column/value dictionary, default empty 878 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 879 moldict -dict, molecule description dictionary 880 **kwarg - ID, IDlist, IDict 881 OUTPUT: 882 ID - id table value 883 """ 884 ############################################################################### 885 tablename='ChainMol' 886 if lowercasetablenames: 887 tablename=tablename.lower() 888 tabcol=['Id','ChainIdFk','MoleculeIdFk']#column names 889 ################################################################################ 890 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 891 print 'Error, %s: Incorrect table description!'%tablename 892 self.log.error('%s: Incorrect table description',tablename) 893 sys.exit(1) 894 if not kwarg.has_key('anyflag'): 895 kwarg.setdefault('anyflag',False) 896 897 indict={}#input list 898 ID=kwarg.get('ID',None) 899 if ID:## ID must be list of length=1 900 if not isinstance(ID,list) or len(ID)!=1: 901 print 'Error, %s: Incorrect ID specification!' %tablename 902 if logdebug: 903 self.log.debug('%s: Incorrect ID specification',tablename) 904 return 0 905 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 906 indict[tabcol[2]]=str(ID[0])#set Molecule foreign key 907 908 IDlist=kwarg.get('IDlist',None) 909 if IDlist:## must be list 910 if not isinstance(IDlist,list): 911 print 'Error, %s: Incorrect IDlist specification!' %tablename 912 if logdebug: 913 self.log.debug('%s: Incorrect IDlist specification',tablename) 914 return 0 915 916 IDict=kwarg.get('IDict',None) 917 if IDict:## must be dictionary 918 if not isinstance(IDict,dict): 919 print 'Error, %s: Incorrect IDict specification!' %tablename 920 if logdebug: 921 self.log.debug('%s: Incorrect IDict specification',tablename) 922 return 0 923 924 moldict=kwarg.get('moldict',None)#get molecule dictionary 925 if not moldict:#no molecule dictionary 926 print 'Warning %s: Molecule dictionary not available!' %tablename 927 if logdebug: 928 self.log.debug('%s: Molecule dictionary not available',tablename) 929 sys.exit(1) 930 931 molchainlist=moldict.get('MolChain',None)#get molecule chain list 932 molchainlist=[molchain for molchain in molchainlist if molchain.isalpha()]#get letters values 933 934 if molchainlist:#if list not empty 935 templist=[] 936 for molchain in molchainlist:#iterate list 937 if IDict.has_key(molchain):#if key in chain dictionary 938 templist.append(IDict[molchain][0]) 939 indict[tabcol[1]]=templist#set Chain foreign key 940 else: 941 return 0 942 else: 943 return 0 944 945 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 946 inskey,insval=insPrep(**inrow)#preparation for insertion to table 947 if kwarg['anyflag']:#remove items with at least False value 948 insval=filter(checkitem,insval) 949 if not all([checkitem(val) for val in insval]):#check all values are True 950 return 0 951 if not insval:##input list is empty 952 return 0 953 954 return self.insertrecord(tablename,inskey,insval,logdebug)
955
956 - def getChainMol(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
957 """ 958 Get ChainMol dictionary for specified Entry 959 INPUT: 960 logdebug - log debug in log file 961 tabcolvalidict - dict, table column/value dictionary, default empty 962 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 963 **kwarg - ID, IDlist, IDict 964 OUTPUT: 965 IDict - dict, model ID dictionary 966 """ 967 ############################################################################### 968 tablename='ChainMol' 969 if lowercasetablenames: 970 tablename=tablename.lower() 971 tabcol=['Id','ChainIdFk','MoleculeIdFk']#column names 972 ################################################################################ 973 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 974 print 'Error, %s: Incorrect table description!'%tablename 975 self.log.error('%s: Incorrect table description',tablename) 976 sys.exit(1) 977 ID=kwarg.get('ID',None) 978 if ID:## ID must be list of length=1 979 if not isinstance(ID,list) or len(ID)!=1: 980 print 'Error, %s: Incorrect ID specification!' %tablename 981 if logdebug: 982 self.log.debug('%s: Incorrect ID specification',tablename) 983 return 0 984 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 985 MoleculeIdFk=str(ID[0])#set Entry foreign key 986 987 else: 988 print 'Error: Specify ID' 989 self.log.error('Specify ID') 990 return 0 991 992 select='Select([table.'+ tablename +'.'+tabcol[2]+',table.'+ tablename +'.'+tabcol[1]+'], where=OR(table.'+tablename+'.'+tabcol[2]+'==MoleculeIdFk))' 993 sql=queryBuilder(eval(select))#build query 994 result=self.executeQuery(sql)#execute query 995 if result: 996 IDlist=[(resultval[tabcol[2]] ,resultval[tabcol[1]]) for resultval in result] 997 IDict={} 998 for IDitem in IDlist: 999 if IDict.has_key(IDitem[0]): 1000 IDict[IDitem[0]][tabcol[1]].append(IDitem[1]) 1001 else: 1002 IDict[IDitem[0]]={tabcol[1]:[IDitem[1]]} 1003 return IDict 1004 else: 1005 return 0
1006
1007 - def getResidue(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1008 """ 1009 Get Residue dictionary for specified Molecules 1010 INPUT: 1011 logdebug - log debug in log file 1012 tabcolvalidict - dict, table column/value dictionary, default empty 1013 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1014 **kwarg - ID, IDlist, IDict 1015 OUTPUT: 1016 ID - id table value 1017 """ 1018 ############################################################################### 1019 tablename='Residue' 1020 if lowercasetablenames: 1021 tablename=tablename.lower() 1022 tabcol=['Id','SeqNum','ResName','ResInsCode','MoleculeIdFk','ChainIdFk','ModelIdFk']#column names 1023 ################################################################################ 1024 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1025 print 'Error, %s: Incorrect table description!'%tablename 1026 self.log.error('%s: Incorrect table description',tablename) 1027 sys.exit(1) 1028 if not kwarg.has_key('anyflag'): 1029 kwarg.setdefault('anyflag',False) 1030 1031 ID=kwarg.get('ID',None) 1032 if ID:## ID must be list of length=1 1033 if not isinstance(ID,list) or len(ID)!=1: 1034 print 'Error, %s: Incorrect ID specification!' %tablename 1035 if logdebug: 1036 self.log.debug('%s: Incorrect ID specification',tablename) 1037 return 0 1038 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1039 MoleculeIdFk=str(ID[0])#set Molecule foreign key 1040 else: 1041 print 'Error: Specify ID' 1042 self.log.error('Specify ID') 1043 return 0 1044 1045 IDlist=kwarg.get('IDlist',None) 1046 if IDlist:## must be list 1047 if not isinstance(IDlist,list): 1048 print 'Error, %s: Incorrect IDlist specification!' %tablename 1049 if logdebug: 1050 self.log.debug('%s: Incorrect IDlist specification',tablename) 1051 return 0 1052 1053 IDict=kwarg.get('IDict',None) 1054 if IDict:## must be dictionary 1055 if not isinstance(IDict,dict): 1056 print 'Error, %s: Incorrect IDict specification!' %tablename 1057 if logdebug: 1058 self.log.debug('%s: Incorrect IDict specification',tablename) 1059 return 0 1060 ModelIdFk=sorted(IDict.keys()) 1061 else: 1062 print 'Error: Specify IDict' 1063 self.log.error('Specify IDict') 1064 return 0 1065 1066 select='Select([table.'+ tablename +'.'+tabcol[0]+ ',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[2]+',table.'+ tablename +'.'+tabcol[3]+',table.'+ tablename +'.'+tabcol[5]+',table.'+ tablename +'.'+tabcol[6]+'], where=AND(table.'+tablename+'.'+tabcol[4]+'==MoleculeIdFk, IN(table.'+tablename+'.'+tabcol[6]+',ModelIdFk) ))' 1067 sql=queryBuilder(eval(select))#build query 1068 result=self.executeQuery(sql)#execute query 1069 if result: 1070 IDict=dict([(item[tabcol[0]],{tabcol[1]:item[tabcol[1]],tabcol[2]:item[tabcol[2]],tabcol[3]:item[tabcol[3]],tabcol[5]:item[tabcol[5]] ,tabcol[6]:item[tabcol[6]] }) for item in result]) 1071 return IDict 1072 else: 1073 return 0
1074
1075 - def Residue(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1076 """ 1077 Residue table import 1078 INPUT: 1079 logdebug - log debug in log file 1080 tabcolvalidict - dict, table column/value dictionary, default empty 1081 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1082 moldict -dict, molecule description dictionary 1083 **kwarg - ID, IDlist, IDict 1084 OUTPUT: 1085 ID - id table value 1086 """ 1087 ############################################################################### 1088 tablename='Residue' 1089 if lowercasetablenames: 1090 tablename=tablename.lower() 1091 tabcol=['Id','SeqNum','ResName','ResInsCode','MoleculeIdFk','ChainIdFk','ModelIdFk']#column names 1092 ################################################################################ 1093 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1094 print 'Error, %s: Incorrect table description!'%tablename 1095 self.log.error('%s: Incorrect table description',tablename) 1096 sys.exit(1) 1097 if not kwarg.has_key('anyflag'): 1098 kwarg.setdefault('anyflag',False) 1099 1100 indict={}#input list 1101 ID=kwarg.get('ID',None) 1102 if ID:## ID must be list of length=1 1103 if not isinstance(ID,list) or len(ID)!=1: 1104 print 'Error, %s: Incorrect ID specification!' %tablename 1105 if logdebug: 1106 self.log.debug('%s: Incorrect ID specification',tablename) 1107 return 0 1108 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1109 indict[tabcol[4]]=str(ID[0])#set Molecule foreign key 1110 1111 IDlist=kwarg.get('IDlist',None) 1112 if IDlist:## must be list 1113 if not isinstance(IDlist,list): 1114 print 'Error, %s: Incorrect IDlist specification!' %tablename 1115 if logdebug: 1116 self.log.debug('%s: Incorrect IDlist specification',tablename) 1117 return 0 1118 1119 IDict=kwarg.get('IDict',None) 1120 if IDict:## must be dictionary 1121 if not isinstance(IDict,dict): 1122 print 'Error, %s: Incorrect IDict specification!' %tablename 1123 if logdebug: 1124 self.log.debug('%s: Incorrect IDict specification',tablename) 1125 return 0 1126 1127 chainidict=IDict.get('ChainIDict',None) 1128 modelidict=IDict.get('ModelIDict',None) 1129 if not(chainidict and modelidict): 1130 print 'Error, %s: Chain or Model foreign keys not available!' %tablename 1131 if logdebug: 1132 self.log.debug('%s: Chain or Model foreign keys not available!',tablename) 1133 sys.exit(1) 1134 1135 mackey=kwarg.get('mackey',None)#get macromolecule key 1136 macval=kwarg.get('macval',None)#get macromolecule value 1137 if not (mackey and macval): 1138 return 0 1139 1140 moldict=kwarg.get('moldict',None)#get molecule dictionary 1141 if not moldict:#no molecule dictionary 1142 print 'Warning %s: Molecule dictionary not available!' %tablename 1143 if logdebug: 1144 self.log.debug('%s: Molecule dictionary not available',tablename) 1145 sys.exit(1) 1146 1147 molchainlist=moldict.get('MolChain',None)#get molecule chain list 1148 molchainlist=[molchain for molchain in molchainlist if molchain.isalpha()]#get letters values 1149 if molchainlist:#if list not empty 1150 if macval.getype()=='P': #if molecule is protein 1151 macmolchainid=macval.getchainid()#get chain id 1152 macmolmodelid=macval.getmodelid()#get model id 1153 if macmolchainid in molchainlist: 1154 if chainidict.has_key(macmolchainid) and modelidict.has_key(macmolmodelid): 1155 indict[tabcol[1]]=str(macval.getmolid())#set molecule id 1156 indict[tabcol[2]]=macval.getmolname()#set molecule name 1157 indict[tabcol[5]]=chainidict[macmolchainid][0]#set chain foreign key 1158 indict[tabcol[6]]=modelidict[macmolmodelid][0]#set model foreign key 1159 1160 resinscode=macval.getmolinscode()#get molecule insertion code 1161 if resinscode.isalpha():#if insertion code is letter 1162 indict[tabcol[3]]=resinscode 1163 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 1164 inskey,insval=insPrep(**inrow)#preparation for insertion to table 1165 if kwarg['anyflag']:#remove items with at least False value 1166 insval=filter(checkitem,insval) 1167 if not all([checkitem(val) for val in insval]):#check all values are True 1168 return 0 1169 if not insval:##input list is empty 1170 return 0 1171 1172 return self.insertrecord(tablename,inskey,insval,logdebug) 1173 else: 1174 print 'Warning: Macromolecule chain and model foreign keys for model: %s, chain: %s, residue: %s not available!'%(macmolmodelid,macmolchainid,macval.getmolname()) 1175 if logdebug: 1176 self.log.debug('%s: Macromolecule chain and model foreign keys for model: %s, chain: %s, residue: %s not available',tablename,macmolmodelid,macmolchainid,macval.getmolname()) 1177 return 0 1178 else: 1179 return 0 # not in chain list 1180 else: 1181 return 0 #not protein
1182
1183 - def ReSSBond(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1184 """ 1185 Residue disulfide bonds table import 1186 INPUT: 1187 logdebug - log debug in log file 1188 tabcolvalidict - dict, table column/value dictionary, default empty 1189 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1190 moldict -dict, molecule description dictionary 1191 **kwarg - ID, IDlist, IDict 1192 OUTPUT: 1193 ID - id table value 1194 """ 1195 ############################################################################### 1196 tablename='ReSSBond' 1197 if lowercasetablenames: 1198 tablename=tablename.lower() 1199 tabcol=['Id','SeqNum','ResName','ResInsCode','ChainIdFk','ResidueIdFk']#column names 1200 ################################################################################ 1201 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1202 print 'Error, %s: Incorrect table description!'%tablename 1203 self.log.error('%s: Incorrect table description',tablename) 1204 sys.exit(1) 1205 if not kwarg.has_key('anyflag'): 1206 kwarg.setdefault('anyflag',False) 1207 1208 indict={}#input list 1209 ID=kwarg.get('ID',None) 1210 if ID:## ID must be list of length=1 1211 if not isinstance(ID,list) or len(ID)!=1: 1212 print 'Error, %s: Incorrect ID specification!' %tablename 1213 if logdebug: 1214 self.log.debug('%s: Incorrect ID specification',tablename) 1215 return 0 1216 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1217 indict[tabcol[5]]=str(ID[0])#set Molecule foreign key 1218 1219 IDlist=kwarg.get('IDlist',None) 1220 if IDlist:## must be list 1221 if not isinstance(IDlist,list): 1222 print 'Error, %s: Incorrect IDlist specification!' %tablename 1223 if logdebug: 1224 self.log.debug('%s: Incorrect IDlist specification',tablename) 1225 return 0 1226 1227 IDict=kwarg.get('IDict',None) 1228 if IDict:## must be dictionary 1229 if not isinstance(IDict,dict): 1230 print 'Error, %s: Incorrect IDict specification!' %tablename 1231 if logdebug: 1232 self.log.debug('%s: Incorrect IDict specification',tablename) 1233 return 0 1234 1235 mackey=kwarg.get('mackey',None)#get macromolecule key 1236 macval=kwarg.get('macval',None)#get macromolecule value 1237 if not (mackey and macval): 1238 return 0 1239 1240 ssbondict=kwarg.get('ssbondict',None)#get molecule dictionary 1241 if not ssbondict:#no molecule dictionary 1242 print 'Warning %s: Residue SSBond dictionary not available!' %tablename 1243 if logdebug: 1244 self.log.debug('%s: Residue SSBond dictionary not available',tablename) 1245 sys.exit(1) 1246 1247 chainid=macval.getchainid()#get molecule chain 1248 resid=macval.getmolid()#get molecule sequence number 1249 resinscode=macval.getmolinscode()#get molecule insertion code 1250 if chainid.isspace(): 1251 if resinscode.isspace(): 1252 resid='%s' %(resid) 1253 else: 1254 resid='%s%s' %(resid,resinscode) 1255 else: 1256 if resinscode.isspace(): 1257 resid='%s_%s' %(chainid,resid) 1258 else: 1259 resid='%s_%s%s'%(chainid,resid,resinscode) 1260 1261 if ssbondict.has_key(resid): 1262 ssbondlist=ssbondict[resid] 1263 if ssbondlist[2].isdigit(): 1264 indict[tabcol[1]]=ssbondlist[2] 1265 if ssbondlist[0].isalpha() and (len(ssbondlist[0])==3): 1266 indict[tabcol[2]]=ssbondlist[0] 1267 if ssbondlist[3].isalpha(): 1268 indict[tabcol[3]]=ssbondlist[3] 1269 if IDict.has_key(ssbondlist[1]): 1270 indict[tabcol[4]]=IDict[ssbondlist[1]][0] 1271 1272 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 1273 inskey,insval=insPrep(**inrow)#preparation for insertion to table 1274 if kwarg['anyflag']:#remove items with at least False value 1275 insval=filter(checkitem,insval) 1276 if not all([checkitem(val) for val in insval]):#check all values are True 1277 return 0 1278 if not insval:##input list is empty 1279 return 0 1280 1281 return self.insertrecord(tablename,inskey,insval,logdebug)
1282
1283 - def getResAtoms(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1284 """ 1285 Get Atoms table import 1286 INPUT: 1287 logdebug - log debug in log file 1288 tabcolvalidict - dict, table column/value dictionary, default empty 1289 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1290 **kwarg - ID, IDlist, IDict 1291 OUTPUT: 1292 ID - id table value 1293 """ 1294 ############################################################################### 1295 tablename='ResAtoms' 1296 if lowercasetablenames: 1297 tablename=tablename.lower() 1298 tabcol=['Id','AtSeqNum','AtPDBSymbol','ElemTabIdFk','ResidueIdFk','AltLocIdFk']#column names 1299 ################################################################################ 1300 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1301 print 'Error, %s: Incorrect table description!'%tablename 1302 self.log.error('%s: Incorrect table description',tablename) 1303 sys.exit(1) 1304 if not kwarg.has_key('anyflag'): 1305 kwarg.setdefault('anyflag',False) 1306 1307 indict={}#input list 1308 ID=kwarg.get('ID',None) 1309 if ID:## ID must be list of length=1 1310 if not isinstance(ID,list) or len(ID)!=1: 1311 print 'Error, %s: Incorrect ID specification!' %tablename 1312 if logdebug: 1313 self.log.debug('%s: Incorrect ID specification',tablename) 1314 return 0 1315 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1316 ResidueIdFk=str(ID[0])#set Residue foreign key 1317 1318 IDlist=kwarg.get('IDlist',None) 1319 if IDlist:## must be list 1320 if not isinstance(IDlist,list): 1321 print 'Error, %s: Incorrect IDlist specification!' %tablename 1322 if logdebug: 1323 self.log.debug('%s: Incorrect IDlist specification',tablename) 1324 return 0 1325 1326 IDict=kwarg.get('IDict',None) 1327 if IDict:## must be dictionary 1328 if not isinstance(IDict,dict): 1329 print 'Error, %s: Incorrect IDict specification!' %tablename 1330 if logdebug: 1331 self.log.debug('%s: Incorrect IDict specification',tablename) 1332 return 0 1333 select='Select([table.'+ tablename +'.'+tabcol[0]+ ',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[2]+',table.'+ tablename +'.'+tabcol[3]+',table.'+ tablename +'.'+tabcol[5]+'], where=OR(table.'+tablename+'.'+tabcol[4]+'==ResidueIdFk))' 1334 sql=queryBuilder(eval(select))#build query 1335 result=self.executeQuery(sql)#execute query 1336 if result: 1337 IDict=dict([(item[tabcol[0]],{tabcol[1]:item[tabcol[1]],tabcol[2]:item[tabcol[2]],tabcol[3]:item[tabcol[3]],tabcol[5]:item[tabcol[5]] }) for item in result]) 1338 return IDict 1339 else: 1340 return 0
1341
1342 - def ResAtoms(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1343 """ 1344 Residue atoms table import 1345 INPUT: 1346 logdebug - log debug in log file 1347 tabcolvalidict - dict, table column/value dictionary, default empty 1348 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1349 moldict -dict, molecule description dictionary 1350 **kwarg - ID, IDlist, IDict 1351 OUTPUT: 1352 ID - id table value 1353 """ 1354 ############################################################################### 1355 tablename='ResAtoms' 1356 if lowercasetablenames: 1357 tablename=tablename.lower() 1358 tabcol=['Id','AtSeqNum','AtPDBSymbol','ElemTabIdFk','ResidueIdFk','AltLocIdFk']#column names 1359 ################################################################################ 1360 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1361 print 'Error, %s: Incorrect table description!'%tablename 1362 self.log.error('%s: Incorrect table description',tablename) 1363 sys.exit(1) 1364 if not kwarg.has_key('anyflag'): 1365 kwarg.setdefault('anyflag',False) 1366 1367 indict={}#input list 1368 ID=kwarg.get('ID',None) 1369 if ID:## ID must be list of length=1 1370 if not isinstance(ID,list) or len(ID)!=1: 1371 print 'Error, %s: Incorrect ID specification!' %tablename 1372 if logdebug: 1373 self.log.debug('%s: Incorrect ID specification',tablename) 1374 return 0 1375 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1376 indict[tabcol[4]]=str(ID[0])#set Residue foreign key 1377 1378 IDlist=kwarg.get('IDlist',None) 1379 if IDlist:## must be list 1380 if not isinstance(IDlist,list): 1381 print 'Error, %s: Incorrect IDlist specification!' %tablename 1382 if logdebug: 1383 self.log.debug('%s: Incorrect IDlist specification',tablename) 1384 return 0 1385 1386 IDict=kwarg.get('IDict',None) 1387 if IDict:## must be dictionary 1388 if not isinstance(IDict,dict): 1389 print 'Error, %s: Incorrect IDict specification!' %tablename 1390 if logdebug: 1391 self.log.debug('%s: Incorrect IDict specification',tablename) 1392 return 0 1393 1394 mackey=kwarg.get('mackey',None)#get macromolecule key 1395 macval=kwarg.get('macval',None)#get macromolecule value 1396 if not (mackey and macval): 1397 return 0 1398 1399 atoms=macval.getmolatoms()#get molecule atoms 1400 if atoms:# if atoms exist 1401 templist=[]#temporary list 1402 templist1=[]#temporary list 1403 templist2=[]#temporary list 1404 templist3=[]#temporary list 1405 atdict=dict([(atkey, atobj.getatsernum()) for atkey, atobj in atoms.iteritems()])#atom dictionary - atom resideu id : atom serial number 1406 atdict=sortdictval(atdict)#sorted atom list of tuples 1407 for atitem in atdict:#iterate list of tuples 1408 atkey=atitem[0]#atom key 1409 atobj=atoms[atkey]#atom object 1410 atsernum=str(atobj.getatsernum())#get atom serial number 1411 templist.append(atsernum) 1412 atname=atobj.getatname().strip()#get atom pdb name 1413 atname=atname.split('_')#split with underscore 1414 atname=atname[0].strip()#remove blank 1415 templist1.append(atname) 1416 atnum=str(atobj.getatnum())#get element table number 1417 templist2.append(atnum) 1418 ataltloc=atobj.getataltloc()#get atom alternate location 1419 if ataltloc!=' ':# if alternate location exist 1420 if IDict.has_key(ataltloc):#if alternate location foreign key exist 1421 templist3.append(IDict[ataltloc][0]) 1422 indict[tabcol[1]]=templist#set atom sequence number 1423 indict[tabcol[2]]=templist1#set atom pdb symbol 1424 indict[tabcol[3]]=templist2#set atom element table foreign key 1425 if templist3:#if temporaty list not empty 1426 indict[tabcol[5]]=templist3 1427 else:#not atoms available 1428 return 0 1429 1430 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 1431 inskey,insval=insPrep(**inrow)#preparation for insertion to table 1432 if kwarg['anyflag']:#remove items with at least False value 1433 insval=filter(checkitem,insval) 1434 if not all([checkitem(val) for val in insval]):#check all values are True 1435 return 0 1436 if not insval:##input list is empty 1437 return 0 1438 1439 return self.insertrecord(tablename,inskey,insval,logdebug)
1440
1441 - def getResAtomStat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1442 """ 1443 Get Residue atom state table for specified Residue 1444 INPUT: 1445 logdebug - log debug in log file 1446 tabcolvalidict - dict, table column/value dictionary, default empty 1447 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1448 **kwarg - ID, IDlist, IDict 1449 OUTPUT: 1450 ID - id table value 1451 """ 1452 ############################################################################### 1453 tablename='ResAtomStat' 1454 if lowercasetablenames: 1455 tablename=tablename.lower() 1456 tabcol=['Id','posX','posY','posZ','AtOccup','AtBFact','ResidueIdFk','ResAtomsIdFk']#column names 1457 ################################################################################ 1458 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1459 print 'Error, %s: Incorrect table description!'%tablename 1460 self.log.error('%s: Incorrect table description',tablename) 1461 sys.exit(1) 1462 if not kwarg.has_key('anyflag'): 1463 kwarg.setdefault('anyflag',False) 1464 1465 indict={}#input list 1466 ID=kwarg.get('ID',None) 1467 if ID:## ID must be list of length=1 1468 if not isinstance(ID,list) or len(ID)!=1: 1469 print 'Error, %s: Incorrect ID specification!' %tablename 1470 if logdebug: 1471 self.log.debug('%s: Incorrect ID specification',tablename) 1472 return 0 1473 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1474 ResidueIdFk=str(ID[0])#set ResConfStat foreign key 1475 1476 IDlist=kwarg.get('IDlist',None) 1477 if IDlist:## must be list 1478 if not isinstance(IDlist,list): 1479 print 'Error, %s: Incorrect IDlist specification!' %tablename 1480 if logdebug: 1481 self.log.debug('%s: Incorrect IDlist specification',tablename) 1482 return 0 1483 indict[tabcol[7]]=IDlist#set Atoms foreign key list 1484 1485 IDict=kwarg.get('IDict',None) 1486 if IDict:## must be dictionary 1487 if not isinstance(IDict,dict): 1488 print 'Error, %s: Incorrect IDict specification!' %tablename 1489 if logdebug: 1490 self.log.debug('%s: Incorrect IDict specification',tablename) 1491 return 0 1492 select='Select([table.'+ tablename +'.'+tabcol[1]+ ',table.'+ tablename +'.'+tabcol[2]+',table.'+ tablename +'.'+tabcol[3]+',table.'+ tablename +'.'+tabcol[4]+',table.'+ tablename +'.'+tabcol[5]+ ',table.'+ tablename +'.'+tabcol[7]+'], where=OR(table.'+tablename+'.'+tabcol[6]+'==ResidueIdFk))' 1493 sql=queryBuilder(eval(select))#build query 1494 result=self.executeQuery(sql)#execute query 1495 if result: 1496 IDict=dict([(item[tabcol[7]],[item[tabcol[1]],item[tabcol[2]],item[tabcol[3]],item[tabcol[4]],item[tabcol[5]] ]) for item in result]) 1497 return IDict 1498 else: 1499 return 0
1500
1501 - def ResAtomStat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1502 """ 1503 Residue atom state table import 1504 INPUT: 1505 logdebug - log debug in log file 1506 tabcolvalidict - dict, table column/value dictionary, default empty 1507 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1508 moldict -dict, molecule description dictionary 1509 **kwarg - ID, IDlist, IDict 1510 OUTPUT: 1511 ID - id table value 1512 """ 1513 ############################################################################### 1514 tablename='ResAtomStat' 1515 if lowercasetablenames: 1516 tablename=tablename.lower() 1517 tabcol=['Id','posX','posY','posZ','AtOccup','AtBFact','ResidueIdFk','ResAtomsIdFk']#column names 1518 ################################################################################ 1519 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1520 print 'Error, %s: Incorrect table description!'%tablename 1521 self.log.error('%s: Incorrect table description',tablename) 1522 sys.exit(1) 1523 if not kwarg.has_key('anyflag'): 1524 kwarg.setdefault('anyflag',False) 1525 1526 indict={}#input list 1527 ID=kwarg.get('ID',None) 1528 if ID:## ID must be list of length=1 1529 if not isinstance(ID,list) or len(ID)!=1: 1530 print 'Error, %s: Incorrect ID specification!' %tablename 1531 if logdebug: 1532 self.log.debug('%s: Incorrect ID specification',tablename) 1533 return 0 1534 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1535 indict[tabcol[6]]=str(ID[0])#set ResConfStat foreign key 1536 1537 IDlist=kwarg.get('IDlist',None) 1538 if IDlist:## must be list 1539 if not isinstance(IDlist,list): 1540 print 'Error, %s: Incorrect IDlist specification!' %tablename 1541 if logdebug: 1542 self.log.debug('%s: Incorrect IDlist specification',tablename) 1543 return 0 1544 indict[tabcol[7]]=IDlist#set Atoms foreign key list 1545 1546 IDict=kwarg.get('IDict',None) 1547 if IDict:## must be dictionary 1548 if not isinstance(IDict,dict): 1549 print 'Error, %s: Incorrect IDict specification!' %tablename 1550 if logdebug: 1551 self.log.debug('%s: Incorrect IDict specification',tablename) 1552 return 0 1553 1554 mackey=kwarg.get('mackey',None)#get macromolecule key 1555 macval=kwarg.get('macval',None)#get macromolecule value 1556 if not (mackey and macval): 1557 return 0 1558 1559 atoms=macval.getmolatoms()#get molecule atoms 1560 if atoms:# if atoms exist 1561 templist=[]#temporary list 1562 templist1=[]#temporary list 1563 templist2=[]#temporary list 1564 templist3=[]#temporary list 1565 templist4=[]#temporary list 1566 atdict=dict([(atkey, atobj.getatsernum()) for atkey, atobj in atoms.iteritems()])#atom dictionary - atom resideu id : atom serial number 1567 atdict=sortdictval(atdict)#sorted atom list of tuples 1568 for atitem in atdict:#iterate list of tuples 1569 atkey=atitem[0]#atom key 1570 atobj=atoms[atkey]#atom object 1571 coords=atobj.getatcoords()#get coordinate tuple 1572 if coords: 1573 if isinstance(coords, (list,tuple)):#check if tuple or list 1574 try: 1575 posX=coords[0] 1576 posY=coords[1] 1577 posZ=coords[2] 1578 except IndexError: 1579 return 0 1580 templist.append(posX) 1581 templist1.append(posY) 1582 templist2.append(posZ) 1583 else: 1584 return 0 1585 else: 1586 return 0 1587 1588 atoccup=atobj.getatoccup()#get atom occupancy 1589 templist3.append(atoccup) 1590 atbfactor=atobj.getatbfactor()#get atom B factor 1591 templist4.append(atbfactor) 1592 1593 indict[tabcol[1]]=templist#set atom sequence number 1594 indict[tabcol[2]]=templist1#set atom pdb symbol 1595 indict[tabcol[3]]=templist2#set atom element table foreign key 1596 indict[tabcol[4]]=templist3#set atom occupancy 1597 indict[tabcol[5]]=templist4#set B factor 1598 1599 else:#not atoms available 1600 return 0 1601 1602 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 1603 inskey,insval=insPrep(**inrow)#preparation for insertion to table 1604 if kwarg['anyflag']:#remove items with at least False value 1605 insval=filter(checkitem,insval) 1606 if not all([checkitem(val) for val in insval]):#check all values are True 1607 return 0 1608 if not insval:##input list is empty 1609 return 0 1610 1611 return self.insertrecord(tablename,inskey,insval,logdebug)
1612
1613 - def getHetMol(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1614 """ 1615 Get HetMol table for specified Molecule 1616 INPUT: 1617 logdebug - log debug in log file 1618 tabcolvalidict - dict, table column/value dictionary, default empty 1619 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1620 moldict -dict, molecule description dictionary 1621 **kwarg - ID, IDlist, IDict 1622 OUTPUT: 1623 ID - id table value 1624 """ 1625 ############################################################################### 1626 tablename='HetMol' 1627 if lowercasetablenames: 1628 tablename=tablename.lower() 1629 tabcol=['Id','SeqNum','PDBNumHetAt','ProtStatIdFk','ConfStatIdFk','ModelIdFk','ChainIdFk','MoleculeIdFk']#column names 1630 ################################################################################ 1631 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1632 print 'Error, %s: Incorrect table description!'%tablename 1633 self.log.error('%s: Incorrect table description',tablename) 1634 sys.exit(1) 1635 if not kwarg.has_key('anyflag'): 1636 kwarg.setdefault('anyflag',False) 1637 1638 ID=kwarg.get('ID',None) 1639 if ID:## ID must be list of length=1 1640 if not isinstance(ID,list) or len(ID)!=1: 1641 print 'Error, %s: Incorrect ID specification!' %tablename 1642 if logdebug: 1643 self.log.debug('%s: Incorrect ID specification',tablename) 1644 return 0 1645 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1646 MoleculeIdFk=str(ID[0])#set Molecule foreign key 1647 else: 1648 print 'Error: Specify ID' 1649 self.log.error('Specify ID') 1650 return 0 1651 1652 IDlist=kwarg.get('IDlist',None) 1653 if IDlist:## must be list 1654 if not isinstance(IDlist,list): 1655 print 'Error, %s: Incorrect IDlist specification!' %tablename 1656 if logdebug: 1657 self.log.debug('%s: Incorrect IDlist specification',tablename) 1658 return 0 1659 1660 IDict=kwarg.get('IDict',None) 1661 if IDict:## must be dictionary 1662 if not isinstance(IDict,dict): 1663 print 'Error, %s: Incorrect IDict specification!' %tablename 1664 if logdebug: 1665 self.log.debug('%s: Incorrect IDict specification',tablename) 1666 return 0 1667 ModelIdFk=sorted(IDict.keys()) 1668 else: 1669 print 'Error: Specify IDict' 1670 self.log.error('Specify IDict') 1671 return 0 1672 1673 select='Select([table.'+ tablename +'.'+tabcol[0]+ ',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[2]+',table.'+ tablename +'.'+tabcol[3]+',table.'+ tablename +'.'+tabcol[4]+',table.'+ tablename +'.'+tabcol[5]+',table.'+ tablename +'.'+tabcol[6]+'], where=AND(table.'+tablename+'.'+tabcol[7]+'==MoleculeIdFk, IN(table.'+tablename+'.'+tabcol[5]+',ModelIdFk) ))' 1674 sql=queryBuilder(eval(select))#build query 1675 result=self.executeQuery(sql)#execute query 1676 if result: 1677 IDict=dict([(item[tabcol[0]],{tabcol[1]:item[tabcol[1]],tabcol[2]:item[tabcol[2]],tabcol[3]:item[tabcol[3]],tabcol[4]:item[tabcol[4]],tabcol[5]:item[tabcol[5]] ,tabcol[6]:item[tabcol[6]] }) for item in result]) 1678 return IDict 1679 else: 1680 return 0
1681
1682 - def HetMol(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1683 """ 1684 HeteroMolecule table import 1685 INPUT: 1686 logdebug - log debug in log file 1687 tabcolvalidict - dict, table column/value dictionary, default empty 1688 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1689 moldict -dict, molecule description dictionary 1690 **kwarg - ID, IDlist, IDict 1691 OUTPUT: 1692 ID - id table value 1693 """ 1694 ############################################################################### 1695 tablename='HetMol' 1696 if lowercasetablenames: 1697 tablename=tablename.lower() 1698 tabcol=['Id','SeqNum','PDBNumHetAt','ProtStatIdFk','ConfStatIdFk','ModelIdFk','ChainIdFk','MoleculeIdFk']#column names 1699 ################################################################################ 1700 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1701 print 'Error, %s: Incorrect table description!'%tablename 1702 self.log.error('%s: Incorrect table description',tablename) 1703 sys.exit(1) 1704 if not kwarg.has_key('anyflag'): 1705 kwarg.setdefault('anyflag',False) 1706 1707 indict={}#input list 1708 ID=kwarg.get('ID',None) 1709 if ID:## ID must be list of length=1 1710 if not isinstance(ID,list) or len(ID)!=1: 1711 print 'Error, %s: Incorrect ID specification!' %tablename 1712 if logdebug: 1713 self.log.debug('%s: Incorrect ID specification',tablename) 1714 return 0 1715 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1716 indict[tabcol[7]]=str(ID[0])#set Molecule foreign key 1717 1718 IDlist=kwarg.get('IDlist',None) 1719 if IDlist:## must be list 1720 if not isinstance(IDlist,list): 1721 print 'Error, %s: Incorrect IDlist specification!' %tablename 1722 if logdebug: 1723 self.log.debug('%s: Incorrect IDlist specification',tablename) 1724 return 0 1725 1726 IDict=kwarg.get('IDict',None) 1727 if IDict:## must be dictionary 1728 if not isinstance(IDict,dict): 1729 print 'Error, %s: Incorrect IDict specification!' %tablename 1730 if logdebug: 1731 self.log.debug('%s: Incorrect IDict specification',tablename) 1732 return 0 1733 chainidict=IDict.get('ChainIDict',None) 1734 modelidict=IDict.get('ModelIDict',None) 1735 ProtStatID=IDict.get('ProtStatID',None) 1736 PropDefID=IDict.get('PropDefIDict',None) 1737 1738 if not(chainidict and modelidict): 1739 print 'Error, %s: Chain or Model foreign keys not available!' %tablename 1740 if logdebug: 1741 self.log.debug('%s: Chain or Model foreign keys not available!',tablename) 1742 sys.exit(1) 1743 1744 hetkey=kwarg.get('hetkey',None)#get macromolecule key 1745 hetval=kwarg.get('hetval',None)#get macromolecule value 1746 1747 if not (hetkey and hetval): 1748 return 0 1749 1750 moldict=kwarg.get('moldict',None)#get molecule dictionary 1751 if not moldict:#no molecule dictionary 1752 print 'Warning %s: Molecule dictionary not available!' %tablename 1753 if logdebug: 1754 self.log.debug('%s: Molecule dictionary not available',tablename) 1755 sys.exit(1) 1756 1757 molchainlist=moldict.get('MolChain',None)#get molecule chain list 1758 if molchainlist: 1759 molchainlist=[molchain for molchain in molchainlist if molchain.isalpha()]#get letters values 1760 molcode=moldict['MolCode']#get molecule code (always exists) 1761 1762 if hetval.getype()!='P': #not protein 1763 hetmolname=hetval.getmolname().strip()#get molecule name 1764 if hetmolname==molcode:#heteromolecule name equals molecule code (other solutions can be based on isomeric smile) 1765 hetmolchainid=hetval.getchainid()#get chain id 1766 hetmolmodelid=hetval.getmodelid()#get model id 1767 if hetmolchainid!=' ': 1768 if chainidict.has_key(hetmolchainid): 1769 indict[tabcol[6]]=chainidict[hetmolchainid][0]#set chain foreign key 1770 else: 1771 print 'Warning: Heteromolecule chain foreign keys in %s for model: %s, chain: %s, residue: %s not available!'%(tablename,hetmolmodelid,hetmolchainid,hetmolname) 1772 if logdebug: 1773 self.log.debug('%s: Heteromolecule chain foreign keys for model: %s, chain: %s, residue: %s not available',tablename,hetmolmodelid,hetmolchainid,hetmolname) 1774 return 0 1775 1776 if modelidict.has_key(hetmolmodelid): 1777 indict[tabcol[5]]=modelidict[hetmolmodelid][0]#set model foreign key 1778 else: 1779 if hetmolchainid.isalpha(): 1780 print 'Warning: Heteromolecule model foreign keys in %s for model: %s, chain: %s, residue: %s not available!'%(tablename,hetmolmodelid,hetmolchainid,hetmolname) 1781 if logdebug: 1782 self.log.debug('%s: Heteromolecule model foreign keys for model: %s, chain: %s, residue: %s not available',tablename,hetmolmodelid,hetmolchainid,hetmolname) 1783 else: 1784 print 'Warning: Heteromolecule model foreign keys in %s for model: %s, residue: %s not available!'%(tablename,hetmolmodelid,hetmolname) 1785 if logdebug: 1786 self.log.debug('%s: Heteromolecule model foreign keys for model: %s, residue: %s not available',tablename,hetmolmodelid,hetmolname) 1787 return 0 1788 1789 indict[tabcol[1]]=str(hetval.getmolid())#set heteromolecule sequence number 1790 indict[tabcol[2]]=str(hetval.getmolatnum())#set heteromolecule atom number 1791 if self.ligandb: 1792 if not ProtStatID: 1793 if hetmolchainid.isalpha(): 1794 print 'Error: Ligand ProtStat foreign key in %s for model: %s, chain: %s, residue: %s not available! Please, check setting for addH in addConf or ligadb in MacMolImport function.'%(tablename,hetmolmodelid,hetmolchainid,hetmolname) 1795 if logdebug: 1796 self.log.debug('%s: Ligand ProtStat foreign key for model: %s, chain: %s, residue: %s not available. Please, check setting for addH in addConf or ligadb in MacMolImport function.',tablename,hetmolmodelid,hetmolchainid,hetmolname) 1797 else: 1798 print 'Error: Ligand ProtStat foreign key in %s for model: %s, residue: %s not available! Please, check setting for addH in addConf function or ligadb in MacMolImport function.'%(tablename,hetmolmodelid,hetmolname) 1799 if logdebug: 1800 self.log.debug('%s: Ligand ProtStat foreign key for model: %s, residue: %s not available. Please, check setting for addH in addConf function or ligadb in MacMolImport function.',tablename,hetmolmodelid,hetmolname) 1801 return 0 1802 1803 indictobj=hetval.getcoords() 1804 indictobj['filename']=hetval.getisosmi() 1805 indictobj['property']={} 1806 dictobj=InputDB(**indictobj) 1807 macdbname=self.kwargs['db']#get macromolecule database name 1808 self.kwargs['db']=self.ligandb 1809 ### import to ConfStat table ### 1810 ProtStatID=[long(ID) for ID in ProtStatID] 1811 ConfStatID=self.ConfStat(dictobj,logdebug=logdebug,lowercasetablenames=lowercasetablenames,ID=ProtStatID) 1812 if not ConfStatID: 1813 print 'Error: Ligand ConfStat foreign key in %s for model: %s, chain: %s, residue: %s not available!'%(tablename,hetmolmodelid,hetmolchainid,hetmolname) 1814 if logdebug: 1815 self.log.debug('%s: Ligand ConfStat foreign key for model: %s, chain: %s, residue: %s not available',tablename,hetmolmodelid,hetmolchainid,hetmolname) 1816 sys.exit(1) 1817 ### import to AtomStat table ### 1818 AtomsID=[long(ID) for ID in IDlist] 1819 AtomStatID=self.AtomStat(dictobj,lowercasetablenames=lowercasetablenames,ID=ConfStatID,IDlist=AtomsID) 1820 if not AtomStatID: 1821 print 'Error: Ligand AtomStat foreign key in %s for model: %s, chain: %s, residue: %s not available!'%(tablename,hetmolmodelid,hetmolchainid,hetmolname) 1822 if logdebug: 1823 self.log.debug('%s: Ligand AtomStat foreign key for model: %s, chain: %s, residue: %s not available',tablename,hetmolmodelid,hetmolchainid,hetmolname) 1824 sys.exit(1) 1825 1826 proptabcol= ['Id', 'PropVal', 'PropDefIdFk', 'AtomStatIdFk']#table columname list 1827 ###import to PropAtomStatInt table 1828 proptablename='PropAtomStatInt'#tablename 1829 propmapdict=['autoincrement', 'coords[6]:AtSeqNum','IDict', 'IDlist']# mapping dictionary object attributes 1830 PropProtStatIDInt=self.Prop2Tab(proptablename,proptabcol,propmapdict,dictobj,anyflag=kwarg['anyflag'],logdebug=logdebug,lowercasetablenames=lowercasetablenames,IDcheck=True,IDict=PropDefID,IDlist=AtomStatID) 1831 1832 propmapdict=['autoincrement', 'coords[5]:Charge','IDict', 'IDlist']# mapping dictionary object attributes 1833 PropProtStatIDFloat=self.Prop2Tab(proptablename,proptabcol,propmapdict,dictobj,anyflag=kwarg['anyflag'],logdebug=logdebug,lowercasetablenames=lowercasetablenames,IDcheck=True,IDict=PropDefID,IDlist=AtomStatID) 1834 1835 ###import to PropAtomStatText table 1836 proptablename='PropAtomStatText'#tablename 1837 #proptabcol= ['Id', 'PropVal', 'PropDefIdFk', 'AtomStatIdFk']#table columname list 1838 propmapdict=['autoincrement', 'coords[7]:AtPDBSymbol','IDict', 'IDlist']# mapping dictionary object attributes 1839 PropProtStatIDText=self.Prop2Tab(proptablename,proptabcol,propmapdict,dictobj,anyflag=kwarg['anyflag'],logdebug=logdebug,lowercasetablenames=lowercasetablenames,IDcheck=True,IDict=PropDefID,IDlist=AtomStatID) 1840 1841 propmapdict=['autoincrement', 'coords[10]:AtAltLoc','IDict', 'IDlist']# mapping dictionary object attributes 1842 PropProtStatIDText=self.Prop2Tab(proptablename,proptabcol,propmapdict,dictobj,anyflag=kwarg['anyflag'],logdebug=logdebug,lowercasetablenames=lowercasetablenames,IDcheck=True,IDict=PropDefID,IDlist=AtomStatID) 1843 1844 propmapdict=['autoincrement', 'coords[11]:AtInsCode','IDict', 'IDlist']# mapping dictionary object attributes 1845 PropProtStatIDText=self.Prop2Tab(proptablename,proptabcol,propmapdict,dictobj,anyflag=kwarg['anyflag'],logdebug=logdebug,lowercasetablenames=lowercasetablenames,IDcheck=True,IDict=PropDefID,IDlist=AtomStatID) 1846 1847 ###import to PropAtomStatFloat table 1848 proptablename='PropAtomStatFloat'#tablename 1849 #proptabcol= ['Id', 'PropVal', 'PropDefIdFk', 'AtomStatIdFk']#table columname list 1850 propmapdict=['autoincrement', 'coords[8]:AtOccup','IDict', 'IDlist']# mapping dictionary object attributes 1851 PropProtStatIDFloat=self.Prop2Tab(proptablename,proptabcol,propmapdict,dictobj,anyflag=kwarg['anyflag'],logdebug=logdebug,lowercasetablenames=lowercasetablenames,IDcheck=True,IDict=PropDefID,IDlist=AtomStatID) 1852 1853 propmapdict=['autoincrement', 'coords[9]:AtBFactor','IDict', 'IDlist']# mapping dictionary object attributes 1854 PropProtStatIDFloat=self.Prop2Tab(proptablename,proptabcol,propmapdict,dictobj,anyflag=kwarg['anyflag'],logdebug=logdebug,lowercasetablenames=lowercasetablenames,IDcheck=True,IDict=PropDefID,IDlist=AtomStatID) 1855 1856 self.kwargs['db']=macdbname# set db to macromolecule database 1857 if ProtStatID and AtomsID: 1858 indict[tabcol[3]]=ProtStatID 1859 indict[tabcol[4]]=ConfStatID 1860 1861 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 1862 inskey,insval=insPrep(**inrow)#preparation for insertion to table 1863 if kwarg['anyflag']:#remove items with at least False value 1864 insval=filter(checkitem,insval) 1865 if not all([checkitem(val) for val in insval]):#check all values are True 1866 return 0 1867 if not insval:##input list is empty 1868 return 0 1869 1870 return self.insertrecord(tablename,inskey,insval,logdebug) 1871 1872 else:#heteromolecule name != molecule code 1873 return 0 1874 1875 else:#is protein 1876 return 0
1877
1878 - def User(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1879 """ 1880 User table import 1881 INPUT: 1882 logdebug - log debug in log file 1883 tabcolvalidict - dict, table column/value dictionary, default empty 1884 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1885 **kwarg - property definition dictionary 1886 OUTPUT: 1887 ID - id table value 1888 """ 1889 ############################################################################### 1890 tablename='User' 1891 if lowercasetablenames: 1892 tablename=tablename.lower() 1893 tabcol=['Id','UserName','CreationDate','EntryIdFk']#column names 1894 ################################################################################ 1895 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1896 print 'Error, %s: Incorrect table description!'%tablename 1897 self.log.error('%s: Incorrect table description',tablename) 1898 sys.exit(1) 1899 if not kwarg.has_key('anyflag'): 1900 kwarg.setdefault('anyflag',False) 1901 1902 indict={}#input list 1903 ID=kwarg.get('ID',None) 1904 if ID:## ID must be list of length=1 1905 if not isinstance(ID,list) or len(ID)!=1: 1906 print 'Error, %s: Incorrect ID specification!' %tablename 1907 if logdebug: 1908 self.log.debug('%s: Incorrect ID specification',tablename) 1909 return 0 1910 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1911 indict[tabcol[3]]=str(ID[0])#set Molecule foreign key 1912 1913 IDlist=kwarg.get('IDlist',None) 1914 if IDlist:## must be list 1915 if not isinstance(IDlist,list): 1916 print 'Error, %s: Incorrect IDlist specification!' %tablename 1917 if logdebug: 1918 self.log.debug('%s: Incorrect IDlist specification',tablename) 1919 return 0 1920 1921 IDict=kwarg.get('IDict',None) 1922 if IDict:## must be dictionary 1923 if not isinstance(IDict,dict): 1924 print 'Error, %s: Incorrect IDict specification!' %tablename 1925 if logdebug: 1926 self.log.debug('%s: Incorrect IDict specification',tablename) 1927 return 0 1928 1929 username=self.kwargs.get('user',None)#get user name 1930 if not username: 1931 username=getCurrentUser() 1932 indict[tabcol[1]]=username#set user name 1933 1934 datetime=self.getCurrenTime()#get database timestamp 1935 if not datetime: 1936 datetime=getdatetime() 1937 indict[tabcol[2]]=str(datetime)#set timestamp 1938 1939 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 1940 inskey,insval=insPrep(**inrow)#preparation for insertion to table 1941 if kwarg['anyflag']:#remove items with at least False value 1942 insval=filter(checkitem,insval) 1943 if not all([checkitem(val) for val in insval]):#check all values are True 1944 return 0 1945 if not insval:##input list is empty 1946 return 0 1947 1948 return self.insertrecord(tablename,inskey,insval,logdebug)
1949
1950 - def getHeadKeywDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
1951 """ 1952 Get PDB Header key from HeadKeywDat table 1953 INPUT: 1954 logdebug - log debug in log file 1955 tabcolvalidict - dict, table column/value dictionary, default empty 1956 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 1957 **kwarg - property definition dictionary 1958 OUTPUT: 1959 ID - id table value 1960 """ 1961 ############################################################################### 1962 tablename='HeadKeywDat' 1963 if lowercasetablenames: 1964 tablename=tablename.lower() 1965 tabcol=['Id','Class','DepositDate','Title','KeyWords','EntryIdFk']#column names 1966 ################################################################################ 1967 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 1968 print 'Error, %s: Incorrect table description!'%tablename 1969 self.log.error('%s: Incorrect table description',tablename) 1970 sys.exit(1) 1971 1972 ID=kwarg.get('ID',None) 1973 if ID:## ID must be list of length=1 1974 if not isinstance(ID,list) or len(ID)!=1: 1975 print 'Error, %s: Incorrect ID specification!' %tablename 1976 if logdebug: 1977 self.log.debug('%s: Incorrect ID specification',tablename) 1978 return 0 1979 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 1980 EntryIdFk=str(ID[0])#set Molecule foreign key 1981 1982 IDlist=kwarg.get('IDlist',None) 1983 if IDlist:## must be list 1984 if not isinstance(IDlist,list): 1985 print 'Error, %s: Incorrect IDlist specification!' %tablename 1986 if logdebug: 1987 self.log.debug('%s: Incorrect IDlist specification',tablename) 1988 return 0 1989 1990 IDict=kwarg.get('IDict',None) 1991 if IDict:## must be dictionary 1992 if not isinstance(IDict,dict): 1993 print 'Error, %s: Incorrect IDict specification!' %tablename 1994 if logdebug: 1995 self.log.debug('%s: Incorrect IDict specification',tablename) 1996 return 0 1997 1998 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[2]+',table.'+ tablename +'.'+tabcol[3]+',table.'+ tablename +'.'+tabcol[4]+'], where=OR(table.'+tablename+'.'+tabcol[5]+'==EntryIdFk))' 1999 sql=queryBuilder(eval(select))#build query 2000 result=self.executeQuery(sql)#execute query 2001 if result: 2002 return result 2003 else: 2004 return 0
2005
2006 - def HeadKeywDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2007 """ 2008 PDB Header key table import 2009 INPUT: 2010 logdebug - log debug in log file 2011 tabcolvalidict - dict, table column/value dictionary, default empty 2012 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2013 **kwarg - property definition dictionary 2014 OUTPUT: 2015 ID - id table value 2016 """ 2017 ############################################################################### 2018 tablename='HeadKeywDat' 2019 if lowercasetablenames: 2020 tablename=tablename.lower() 2021 tabcol=['Id','Class','DepositDate','Title','KeyWords','EntryIdFk']#column names 2022 ################################################################################ 2023 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2024 print 'Error, %s: Incorrect table description!'%tablename 2025 self.log.error('%s: Incorrect table description',tablename) 2026 sys.exit(1) 2027 if not kwarg.has_key('anyflag'): 2028 kwarg.setdefault('anyflag',False) 2029 2030 indict={}#input list 2031 ID=kwarg.get('ID',None) 2032 if ID:## ID must be list of length=1 2033 if not isinstance(ID,list) or len(ID)!=1: 2034 print 'Error, %s: Incorrect ID specification!' %tablename 2035 if logdebug: 2036 self.log.debug('%s: Incorrect ID specification',tablename) 2037 return 0 2038 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2039 indict[tabcol[5]]=str(ID[0])#set Molecule foreign key 2040 2041 IDlist=kwarg.get('IDlist',None) 2042 if IDlist:## must be list 2043 if not isinstance(IDlist,list): 2044 print 'Error, %s: Incorrect IDlist specification!' %tablename 2045 if logdebug: 2046 self.log.debug('%s: Incorrect IDlist specification',tablename) 2047 return 0 2048 2049 IDict=kwarg.get('IDict',None) 2050 if IDict:## must be dictionary 2051 if not isinstance(IDict,dict): 2052 print 'Error, %s: Incorrect IDict specification!' %tablename 2053 if logdebug: 2054 self.log.debug('%s: Incorrect IDict specification',tablename) 2055 return 0 2056 2057 headkeywdat=kwarg.get('headerdict',None)#get header, keyword dictionary 2058 if headkeywdat:#if not empty 2059 for colname in tabcol: 2060 if headkeywdat.has_key(colname): 2061 indict[colname]=headkeywdat[colname] 2062 2063 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 2064 inskey,insval=insPrep(**inrow)#preparation for insertion to table 2065 if kwarg['anyflag']:#remove items with at least False value 2066 insval=filter(checkitem,insval) 2067 if not all([checkitem(val) for val in insval]):#check all values are True 2068 return 0 2069 if not insval:##input list is empty 2070 return 0 2071 return self.insertrecord(tablename,inskey,insval,logdebug) 2072 else: return 0
2073
2074 - def getExperimDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2075 """ 2076 Get Experimental table data for specified entry 2077 INPUT: 2078 logdebug - log debug in log file 2079 tabcolvalidict - dict, table column/value dictionary, default empty 2080 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2081 **kwarg - property definition dictionary 2082 OUTPUT: 2083 ID - id table value 2084 """ 2085 ############################################################################### 2086 tablename='ExperimDat' 2087 if lowercasetablenames: 2088 tablename=tablename.lower() 2089 tabcol=['Id','ExperimName','EntryIdFk']#column names 2090 ################################################################################ 2091 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2092 print 'Error, %s: Incorrect table description!'%tablename 2093 self.log.error('%s: Incorrect table description',tablename) 2094 sys.exit(1) 2095 if not kwarg.has_key('anyflag'): 2096 kwarg.setdefault('anyflag',False) 2097 2098 ID=kwarg.get('ID',None) 2099 if ID:## ID must be list of length=1 2100 if not isinstance(ID,list) or len(ID)!=1: 2101 print 'Error, %s: Incorrect ID specification!' %tablename 2102 if logdebug: 2103 self.log.debug('%s: Incorrect ID specification',tablename) 2104 return 0 2105 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2106 EntryIdFk=str(ID[0])#set Molecule foreign key 2107 2108 IDlist=kwarg.get('IDlist',None) 2109 if IDlist:## must be list 2110 if not isinstance(IDlist,list): 2111 print 'Error, %s: Incorrect IDlist specification!' %tablename 2112 if logdebug: 2113 self.log.debug('%s: Incorrect IDlist specification',tablename) 2114 return 0 2115 2116 IDict=kwarg.get('IDict',None) 2117 if IDict:## must be dictionary 2118 if not isinstance(IDict,dict): 2119 print 'Error, %s: Incorrect IDict specification!' %tablename 2120 if logdebug: 2121 self.log.debug('%s: Incorrect IDict specification',tablename) 2122 return 0 2123 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[2]+'], where=OR(table.'+tablename+'.'+tabcol[2]+'==EntryIdFk))' 2124 sql=queryBuilder(eval(select))#build query 2125 result=self.executeQuery(sql)#execute query 2126 if result: 2127 return result 2128 else: 2129 return 0
2130
2131 - def ExperimDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2132 """ 2133 Experimental data table import 2134 INPUT: 2135 logdebug - log debug in log file 2136 tabcolvalidict - dict, table column/value dictionary, default empty 2137 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2138 **kwarg - property definition dictionary 2139 OUTPUT: 2140 ID - id table value 2141 """ 2142 ############################################################################### 2143 tablename='ExperimDat' 2144 if lowercasetablenames: 2145 tablename=tablename.lower() 2146 tabcol=['Id','ExperimName','EntryIdFk']#column names 2147 ################################################################################ 2148 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2149 print 'Error, %s: Incorrect table description!'%tablename 2150 self.log.error('%s: Incorrect table description',tablename) 2151 sys.exit(1) 2152 if not kwarg.has_key('anyflag'): 2153 kwarg.setdefault('anyflag',False) 2154 2155 indict={}#input list 2156 ID=kwarg.get('ID',None) 2157 if ID:## ID must be list of length=1 2158 if not isinstance(ID,list) or len(ID)!=1: 2159 print 'Error, %s: Incorrect ID specification!' %tablename 2160 if logdebug: 2161 self.log.debug('%s: Incorrect ID specification',tablename) 2162 return 0 2163 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2164 indict[tabcol[2]]=str(ID[0])#set Molecule foreign key 2165 2166 IDlist=kwarg.get('IDlist',None) 2167 if IDlist:## must be list 2168 if not isinstance(IDlist,list): 2169 print 'Error, %s: Incorrect IDlist specification!' %tablename 2170 if logdebug: 2171 self.log.debug('%s: Incorrect IDlist specification',tablename) 2172 return 0 2173 2174 IDict=kwarg.get('IDict',None) 2175 if IDict:## must be dictionary 2176 if not isinstance(IDict,dict): 2177 print 'Error, %s: Incorrect IDict specification!' %tablename 2178 if logdebug: 2179 self.log.debug('%s: Incorrect IDict specification',tablename) 2180 return 0 2181 2182 expdat=kwarg.get('headerdict',None)#get header, keyword dictionary 2183 if expdat:#if not empty 2184 for colname in tabcol: 2185 if expdat.has_key(colname): 2186 indict[colname]=expdat[colname] 2187 2188 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 2189 inskey,insval=insPrep(**inrow)#preparation for insertion to table 2190 if kwarg['anyflag']:#remove items with at least False value 2191 insval=filter(checkitem,insval) 2192 if not all([checkitem(val) for val in insval]):#check all values are True 2193 return 0 2194 if not insval:##input list is empty 2195 return 0 2196 return self.insertrecord(tablename,inskey,insval,logdebug) 2197 else: return 0
2198
2199 - def getJournalDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2200 """ 2201 Get Journal table data for specified entry 2202 INPUT: 2203 logdebug - log debug in log file 2204 tabcolvalidict - dict, table column/value dictionary, default empty 2205 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2206 **kwarg - property definition dictionary 2207 OUTPUT: 2208 ID - id table value 2209 """ 2210 ############################################################################### 2211 tablename='JournalDat' 2212 if lowercasetablenames: 2213 tablename=tablename.lower() 2214 tabcol=['Id','Author','Title','Journal','Volume','Page','Year','EntryIdFk']#column names 2215 ################################################################################ 2216 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2217 print 'Error, %s: Incorrect table description!'%tablename 2218 self.log.error('%s: Incorrect table description',tablename) 2219 sys.exit(1) 2220 if not kwarg.has_key('anyflag'): 2221 kwarg.setdefault('anyflag',False) 2222 2223 indict={}#input list 2224 ID=kwarg.get('ID',None) 2225 if ID:## ID must be list of length=1 2226 if not isinstance(ID,list) or len(ID)!=1: 2227 print 'Error, %s: Incorrect ID specification!' %tablename 2228 if logdebug: 2229 self.log.debug('%s: Incorrect ID specification',tablename) 2230 return 0 2231 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2232 EntryIdFk=str(ID[0])#set Molecule foreign key 2233 2234 IDlist=kwarg.get('IDlist',None) 2235 if IDlist:## must be list 2236 if not isinstance(IDlist,list): 2237 print 'Error, %s: Incorrect IDlist specification!' %tablename 2238 if logdebug: 2239 self.log.debug('%s: Incorrect IDlist specification',tablename) 2240 return 0 2241 2242 IDict=kwarg.get('IDict',None) 2243 if IDict:## must be dictionary 2244 if not isinstance(IDict,dict): 2245 print 'Error, %s: Incorrect IDict specification!' %tablename 2246 if logdebug: 2247 self.log.debug('%s: Incorrect IDict specification',tablename) 2248 return 0 2249 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[2]+',table.'+ tablename +'.'+tabcol[3]+',table.'+ tablename +'.'+tabcol[4]+',table.'+ tablename +'.'+tabcol[5]+',table.'+ tablename +'.'+tabcol[6]+'], where=OR(table.'+tablename+'.'+tabcol[7]+'==EntryIdFk))' 2250 sql=queryBuilder(eval(select))#build query 2251 result=self.executeQuery(sql)#execute query 2252 if result: 2253 return result 2254 else: 2255 return 0
2256
2257 - def JournalDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2258 """ 2259 Journal data table import 2260 INPUT: 2261 logdebug - log debug in log file 2262 tabcolvalidict - dict, table column/value dictionary, default empty 2263 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2264 **kwarg - property definition dictionary 2265 OUTPUT: 2266 ID - id table value 2267 """ 2268 ############################################################################### 2269 tablename='JournalDat' 2270 if lowercasetablenames: 2271 tablename=tablename.lower() 2272 tabcol=['Id','Author','Title','Journal','Volume','Page','Year','EntryIdFk']#column names 2273 ################################################################################ 2274 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2275 print 'Error, %s: Incorrect table description!'%tablename 2276 self.log.error('%s: Incorrect table description',tablename) 2277 sys.exit(1) 2278 if not kwarg.has_key('anyflag'): 2279 kwarg.setdefault('anyflag',False) 2280 2281 indict={}#input list 2282 ID=kwarg.get('ID',None) 2283 if ID:## ID must be list of length=1 2284 if not isinstance(ID,list) or len(ID)!=1: 2285 print 'Error, %s: Incorrect ID specification!' %tablename 2286 if logdebug: 2287 self.log.debug('%s: Incorrect ID specification',tablename) 2288 return 0 2289 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2290 indict[tabcol[7]]=str(ID[0])#set Molecule foreign key 2291 2292 IDlist=kwarg.get('IDlist',None) 2293 if IDlist:## must be list 2294 if not isinstance(IDlist,list): 2295 print 'Error, %s: Incorrect IDlist specification!' %tablename 2296 if logdebug: 2297 self.log.debug('%s: Incorrect IDlist specification',tablename) 2298 return 0 2299 2300 IDict=kwarg.get('IDict',None) 2301 if IDict:## must be dictionary 2302 if not isinstance(IDict,dict): 2303 print 'Error, %s: Incorrect IDict specification!' %tablename 2304 if logdebug: 2305 self.log.debug('%s: Incorrect IDict specification',tablename) 2306 return 0 2307 2308 jrnldat=kwarg.get('headerdict',None)#get header, keyword dictionary 2309 if jrnldat: 2310 if jrnldat.has_key('AUTH'): 2311 indict[tabcol[1]]=jrnldat['AUTH'] 2312 if jrnldat.has_key('TITL'): 2313 indict[tabcol[2]]=jrnldat['TITL'] 2314 if jrnldat.has_key('JRNL'): 2315 indict[tabcol[3]]=jrnldat['JRNL'] 2316 if jrnldat.has_key('VOL'): 2317 indict[tabcol[4]]=jrnldat['VOL'] 2318 if jrnldat.has_key('PAGE'): 2319 indict[tabcol[5]]=jrnldat['PAGE'] 2320 if jrnldat.has_key('YEAR'): 2321 indict[tabcol[6]]=jrnldat['YEAR'] 2322 2323 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 2324 inskey,insval=insPrep(**inrow)#preparation for insertion to table 2325 if kwarg['anyflag']:#remove items with at least False value 2326 insval=filter(checkitem,insval) 2327 if not all([checkitem(val) for val in insval]):#check all values are True 2328 return 0 2329 if not insval:##input list is empty 2330 return 0 2331 return self.insertrecord(tablename,inskey,insval,logdebug) 2332 else: return 0
2333
2334 - def getOrigDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2335 """ 2336 Get transformation to submitted coordinates matrix data for specified entry 2337 INPUT: 2338 logdebug - log debug in log file 2339 tabcolvalidict - dict, table column/value dictionary, default empty 2340 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2341 **kwarg - property definition dictionary 2342 OUTPUT: 2343 ID - id table value 2344 transformation formula: 2345 Xsub=O11X+O12Y+O13Z+T1 2346 Ysub=O21X+O22Y+O23Z+T2 2347 Zsub=O31X+O32Y+O33Z+T3 2348 """ 2349 ############################################################################### 2350 tablename='OrigDat' 2351 if lowercasetablenames: 2352 tablename=tablename.lower() 2353 tabcol=['Id','O11','O12','O13','T1','O21','O22','O23','T2','O31','O32','O33','T3','EntryIdFk']#column names 2354 ################################################################################ 2355 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2356 print 'Error, %s: Incorrect table description!'%tablename 2357 self.log.error('%s: Incorrect table description',tablename) 2358 sys.exit(1) 2359 2360 ID=kwarg.get('ID',None) 2361 if ID:## ID must be list of length=1 2362 if not isinstance(ID,list) or len(ID)!=1: 2363 print 'Error, %s: Incorrect ID specification!' %tablename 2364 if logdebug: 2365 self.log.debug('%s: Incorrect ID specification',tablename) 2366 return 0 2367 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2368 EntryIdFk=str(ID[0])#set Molecule foreign key 2369 2370 IDlist=kwarg.get('IDlist',None) 2371 if IDlist:## must be list 2372 if not isinstance(IDlist,list): 2373 print 'Error, %s: Incorrect IDlist specification!' %tablename 2374 if logdebug: 2375 self.log.debug('%s: Incorrect IDlist specification',tablename) 2376 return 0 2377 2378 IDict=kwarg.get('IDict',None) 2379 if IDict:## must be dictionary 2380 if not isinstance(IDict,dict): 2381 print 'Error, %s: Incorrect IDict specification!' %tablename 2382 if logdebug: 2383 self.log.debug('%s: Incorrect IDict specification',tablename) 2384 return 0 2385 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[2]+\ 2386 ',table.'+ tablename +'.'+tabcol[3]+',table.'+ tablename +'.'+tabcol[4]+',table.'+ tablename +'.'+tabcol[5]+',table.'+ tablename +'.'+tabcol[6]+\ 2387 ',table.'+ tablename +'.'+tabcol[7]+',table.'+ tablename +'.'+tabcol[8]+',table.'+ tablename +'.'+tabcol[9]+',table.'+ tablename +'.'+tabcol[10]+\ 2388 ',table.'+ tablename +'.'+tabcol[11]+',table.'+ tablename +'.'+tabcol[12]+\ 2389 '], where=OR(table.'+tablename+'.'+tabcol[13]+'==EntryIdFk))' 2390 sql=queryBuilder(eval(select))#build query 2391 result=self.executeQuery(sql)#execute query 2392 if result: 2393 return result 2394 else: 2395 return 0
2396
2397 - def OrigDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2398 """ 2399 Transformation to submitted coordinates matrix table import 2400 INPUT: 2401 logdebug - log debug in log file 2402 tabcolvalidict - dict, table column/value dictionary, default empty 2403 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2404 **kwarg - property definition dictionary 2405 OUTPUT: 2406 ID - id table value 2407 transformation formula: 2408 Xsub=O11X+O12Y+O13Z+T1 2409 Ysub=O21X+O22Y+O23Z+T2 2410 Zsub=O31X+O32Y+O33Z+T3 2411 """ 2412 ############################################################################### 2413 tablename='OrigDat' 2414 if lowercasetablenames: 2415 tablename=tablename.lower() 2416 tabcol=['Id','O11','O12','O13','T1','O21','O22','O23','T2','O31','O32','O33','T3','EntryIdFk']#column names 2417 ################################################################################ 2418 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2419 print 'Error, %s: Incorrect table description!'%tablename 2420 self.log.error('%s: Incorrect table description',tablename) 2421 sys.exit(1) 2422 if not kwarg.has_key('anyflag'): 2423 kwarg.setdefault('anyflag',False) 2424 2425 indict={}#input list 2426 ID=kwarg.get('ID',None) 2427 if ID:## ID must be list of length=1 2428 if not isinstance(ID,list) or len(ID)!=1: 2429 print 'Error, %s: Incorrect ID specification!' %tablename 2430 if logdebug: 2431 self.log.debug('%s: Incorrect ID specification',tablename) 2432 return 0 2433 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2434 indict[tabcol[13]]=str(ID[0])#set Molecule foreign key 2435 2436 IDlist=kwarg.get('IDlist',None) 2437 if IDlist:## must be list 2438 if not isinstance(IDlist,list): 2439 print 'Error, %s: Incorrect IDlist specification!' %tablename 2440 if logdebug: 2441 self.log.debug('%s: Incorrect IDlist specification',tablename) 2442 return 0 2443 2444 IDict=kwarg.get('IDict',None) 2445 if IDict:## must be dictionary 2446 if not isinstance(IDict,dict): 2447 print 'Error, %s: Incorrect IDict specification!' %tablename 2448 if logdebug: 2449 self.log.debug('%s: Incorrect IDict specification',tablename) 2450 return 0 2451 2452 expdat=kwarg.get('headerdict',None)#get header, keyword dictionary 2453 if expdat:#if not empty 2454 for colname in tabcol: 2455 if expdat.has_key(colname): 2456 indict[colname]=expdat[colname] 2457 2458 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 2459 inskey,insval=insPrep(**inrow)#preparation for insertion to table 2460 if kwarg['anyflag']:#remove items with at least False value 2461 insval=filter(checkitem,insval) 2462 if not all([checkitem(val) for val in insval]):#check all values are True 2463 return 0 2464 if not insval:##input list is empty 2465 return 0 2466 return self.insertrecord(tablename,inskey,insval,logdebug) 2467 else: return 0
2468
2469 - def getScalDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2470 """ 2471 get transformation to fractional crystallographic coordinate table data for specific entry 2472 INPUT: 2473 logdebug - log debug in log file 2474 tabcolvalidict - dict, table column/value dictionary, default empty 2475 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2476 **kwarg - property definition dictionary 2477 OUTPUT: 2478 ID - id table value 2479 transformation formula: 2480 Xfrac=S11X+S12Y+S13Z+U1 2481 Yfrac=S21X+S22Y+S23Z+U2 2482 Zfrac=S31X+S32Y+S33Z+U3 2483 """ 2484 ############################################################################### 2485 tablename='ScalDat' 2486 if lowercasetablenames: 2487 tablename=tablename.lower() 2488 tabcol=['Id','S11','S12','S13','U1','S21','S22','S23','U2','S31','S32','S33','U3','EntryIdFk']#column names 2489 ################################################################################ 2490 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2491 print 'Error, %s: Incorrect table description!'%tablename 2492 self.log.error('%s: Incorrect table description',tablename) 2493 sys.exit(1) 2494 2495 ID=kwarg.get('ID',None) 2496 if ID:## ID must be list of length=1 2497 if not isinstance(ID,list) or len(ID)!=1: 2498 print 'Error, %s: Incorrect ID specification!' %tablename 2499 if logdebug: 2500 self.log.debug('%s: Incorrect ID specification',tablename) 2501 return 0 2502 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2503 EntryIdFk=str(ID[0])#set Molecule foreign key 2504 2505 IDlist=kwarg.get('IDlist',None) 2506 if IDlist:## must be list 2507 if not isinstance(IDlist,list): 2508 print 'Error, %s: Incorrect IDlist specification!' %tablename 2509 if logdebug: 2510 self.log.debug('%s: Incorrect IDlist specification',tablename) 2511 return 0 2512 2513 IDict=kwarg.get('IDict',None) 2514 if IDict:## must be dictionary 2515 if not isinstance(IDict,dict): 2516 print 'Error, %s: Incorrect IDict specification!' %tablename 2517 if logdebug: 2518 self.log.debug('%s: Incorrect IDict specification',tablename) 2519 return 0 2520 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[2]+\ 2521 ',table.'+ tablename +'.'+tabcol[3]+',table.'+ tablename +'.'+tabcol[4]+',table.'+ tablename +'.'+tabcol[5]+',table.'+ tablename +'.'+tabcol[6]+\ 2522 ',table.'+ tablename +'.'+tabcol[7]+',table.'+ tablename +'.'+tabcol[8]+',table.'+ tablename +'.'+tabcol[9]+',table.'+ tablename +'.'+tabcol[10]+\ 2523 ',table.'+ tablename +'.'+tabcol[11]+',table.'+ tablename +'.'+tabcol[12]+\ 2524 '], where=OR(table.'+tablename+'.'+tabcol[13]+'==EntryIdFk))' 2525 sql=queryBuilder(eval(select))#build query 2526 result=self.executeQuery(sql)#execute query 2527 if result: 2528 return result 2529 else: 2530 return 0
2531
2532 - def ScalDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2533 """ 2534 Transformation to fractional crystallographic coordinate data table import 2535 INPUT: 2536 logdebug - log debug in log file 2537 tabcolvalidict - dict, table column/value dictionary, default empty 2538 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2539 **kwarg - property definition dictionary 2540 OUTPUT: 2541 ID - id table value 2542 transformation formula: 2543 Xfrac=S11X+S12Y+S13Z+U1 2544 Yfrac=S21X+S22Y+S23Z+U2 2545 Zfrac=S31X+S32Y+S33Z+U3 2546 """ 2547 ############################################################################### 2548 tablename='ScalDat' 2549 if lowercasetablenames: 2550 tablename=tablename.lower() 2551 tabcol=['Id','S11','S12','S13','U1','S21','S22','S23','U2','S31','S32','S33','U3','EntryIdFk']#column names 2552 ################################################################################ 2553 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2554 print 'Error, %s: Incorrect table description!'%tablename 2555 self.log.error('%s: Incorrect table description',tablename) 2556 sys.exit(1) 2557 if not kwarg.has_key('anyflag'): 2558 kwarg.setdefault('anyflag',False) 2559 2560 indict={}#input list 2561 ID=kwarg.get('ID',None) 2562 if ID:## ID must be list of length=1 2563 if not isinstance(ID,list) or len(ID)!=1: 2564 print 'Error, %s: Incorrect ID specification!' %tablename 2565 if logdebug: 2566 self.log.debug('%s: Incorrect ID specification',tablename) 2567 return 0 2568 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2569 indict[tabcol[13]]=str(ID[0])#set Molecule foreign key 2570 2571 IDlist=kwarg.get('IDlist',None) 2572 if IDlist:## must be list 2573 if not isinstance(IDlist,list): 2574 print 'Error, %s: Incorrect IDlist specification!' %tablename 2575 if logdebug: 2576 self.log.debug('%s: Incorrect IDlist specification',tablename) 2577 return 0 2578 2579 IDict=kwarg.get('IDict',None) 2580 if IDict:## must be dictionary 2581 if not isinstance(IDict,dict): 2582 print 'Error, %s: Incorrect IDict specification!' %tablename 2583 if logdebug: 2584 self.log.debug('%s: Incorrect IDict specification',tablename) 2585 return 0 2586 2587 expdat=kwarg.get('headerdict',None)#get header, keyword dictionary 2588 if expdat:#if not empty 2589 for colname in tabcol: 2590 if expdat.has_key(colname): 2591 indict[colname]=expdat[colname] 2592 2593 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 2594 inskey,insval=insPrep(**inrow)#preparation for insertion to table 2595 if kwarg['anyflag']:#remove items with at least False value 2596 insval=filter(checkitem,insval) 2597 if not all([checkitem(val) for val in insval]):#check all values are True 2598 return 0 2599 if not insval:##input list is empty 2600 return 0 2601 return self.insertrecord(tablename,inskey,insval,logdebug) 2602 else: return 0
2603
2604 - def getMatrixDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2605 """ 2606 Get transformation to fractional crystallographic coordinate table data for specified entry 2607 INPUT: 2608 logdebug - log debug in log file 2609 tabcolvalidict - dict, table column/value dictionary, default empty 2610 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2611 **kwarg - property definition dictionary 2612 OUTPUT: 2613 ID - id table value 2614 """ 2615 ############################################################################### 2616 tablename='MatrixDat' 2617 if lowercasetablenames: 2618 tablename=tablename.lower() 2619 tabcol=['Id','SerNum','M11','M12','M13','V1','iG1','M21','M22','M23','V2','iG2','M31','M32','M33','V3','iG3','EntryIdFk']#column names 2620 ################################################################################ 2621 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2622 print 'Error, %s: Incorrect table description!'%tablename 2623 self.log.error('%s: Incorrect table description',tablename) 2624 sys.exit(1) 2625 2626 ID=kwarg.get('ID',None) 2627 if ID:## ID must be list of length=1 2628 if not isinstance(ID,list) or len(ID)!=1: 2629 print 'Error, %s: Incorrect ID specification!' %tablename 2630 if logdebug: 2631 self.log.debug('%s: Incorrect ID specification',tablename) 2632 return 0 2633 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2634 EntryIdFk=str(ID[0])#set Molecule foreign key 2635 2636 IDlist=kwarg.get('IDlist',None) 2637 if IDlist:## must be list 2638 if not isinstance(IDlist,list): 2639 print 'Error, %s: Incorrect IDlist specification!' %tablename 2640 if logdebug: 2641 self.log.debug('%s: Incorrect IDlist specification',tablename) 2642 return 0 2643 2644 IDict=kwarg.get('IDict',None) 2645 if IDict:## must be dictionary 2646 if not isinstance(IDict,dict): 2647 print 'Error, %s: Incorrect IDict specification!' %tablename 2648 if logdebug: 2649 self.log.debug('%s: Incorrect IDict specification',tablename) 2650 return 0 2651 select='Select([table.'+ tablename +'.'+tabcol[0]+',table.'+ tablename +'.'+tabcol[1]+',table.'+ tablename +'.'+tabcol[2]+\ 2652 ',table.'+ tablename +'.'+tabcol[3]+',table.'+ tablename +'.'+tabcol[4]+',table.'+ tablename +'.'+tabcol[5]+',table.'+ tablename +'.'+tabcol[6]+\ 2653 ',table.'+ tablename +'.'+tabcol[7]+',table.'+ tablename +'.'+tabcol[8]+',table.'+ tablename +'.'+tabcol[9]+',table.'+ tablename +'.'+tabcol[10]+\ 2654 ',table.'+ tablename +'.'+tabcol[11]+',table.'+ tablename +'.'+tabcol[12]+',table.'+ tablename +'.'+tabcol[13]+',table.'+ tablename +'.'+tabcol[14]+\ 2655 ',table.'+ tablename +'.'+tabcol[15]+',table.'+ tablename+'.' +tabcol[16]+\ 2656 '], where=OR(table.'+tablename+'.'+tabcol[17]+'==EntryIdFk))' 2657 sql=queryBuilder(eval(select))#build query 2658 result=self.executeQuery(sql)#execute query 2659 if result: 2660 return result 2661 else: 2662 return 0
2663
2664 - def MatrixDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2665 """ 2666 Transformation to fractional crystallographic coordinate data table import 2667 INPUT: 2668 logdebug - log debug in log file 2669 tabcolvalidict - dict, table column/value dictionary, default empty 2670 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2671 **kwarg - property definition dictionary 2672 OUTPUT: 2673 ID - id table value 2674 """ 2675 ############################################################################### 2676 tablename='MatrixDat' 2677 if lowercasetablenames: 2678 tablename=tablename.lower() 2679 tabcol=['Id','SerNum','M11','M12','M13','V1','iG1','M21','M22','M23','V2','iG2','M31','M32','M33','V3','iG3','EntryIdFk']#column names 2680 ################################################################################ 2681 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2682 print 'Error, %s: Incorrect table description!'%tablename 2683 self.log.error('%s: Incorrect table description',tablename) 2684 sys.exit(1) 2685 if not kwarg.has_key('anyflag'): 2686 kwarg.setdefault('anyflag',False) 2687 2688 indict={}#input list 2689 ID=kwarg.get('ID',None) 2690 if ID:## ID must be list of length=1 2691 if not isinstance(ID,list) or len(ID)!=1: 2692 print 'Error, %s: Incorrect ID specification!' %tablename 2693 if logdebug: 2694 self.log.debug('%s: Incorrect ID specification',tablename) 2695 return 0 2696 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2697 indict[tabcol[17]]=str(ID[0])#set Molecule foreign key 2698 2699 IDlist=kwarg.get('IDlist',None) 2700 if IDlist:## must be list 2701 if not isinstance(IDlist,list): 2702 print 'Error, %s: Incorrect IDlist specification!' %tablename 2703 if logdebug: 2704 self.log.debug('%s: Incorrect IDlist specification',tablename) 2705 return 0 2706 2707 IDict=kwarg.get('IDict',None) 2708 if IDict:## must be dictionary 2709 if not isinstance(IDict,dict): 2710 print 'Error, %s: Incorrect IDict specification!' %tablename 2711 if logdebug: 2712 self.log.debug('%s: Incorrect IDict specification',tablename) 2713 return 0 2714 2715 expdat=kwarg.get('headerdict',None)#get header, keyword dictionary 2716 if expdat:#if not empty 2717 for colname in tabcol: 2718 if expdat.has_key(colname): 2719 indict[colname]=expdat[colname] 2720 2721 inrow=self.validrecord(tablename,tabcol,indict,logdebug)#validate records 2722 inskey,insval=insPrep(**inrow)#preparation for insertion to table 2723 if kwarg['anyflag']:#remove items with at least False value 2724 insval=filter(checkitem,insval) 2725 if not all([checkitem(val) for val in insval]):#check all values are True 2726 return 0 2727 if not insval:##input list is empty 2728 return 0 2729 return self.insertrecord(tablename,inskey,insval,logdebug) 2730 else: return 0
2731
2732 - def getDBRefDat(self,logdebug=False,tabcolvaldict={},lowercasetablenames=True,**kwarg):
2733 """ 2734 Get cross-reference database links data for specified entry 2735 INPUT: 2736 logdebug - log debug in log file 2737 tabcolvalidict - dict, table column/value dictionary, default empty 2738 lowercasetablenames - boolean, lower case table names MySQL engine settings, default True 2739 **kwarg - property definition dictionary 2740 OUTPUT: 2741 ID - id table value 2742 """ 2743 ############################################################################### 2744 tablename='DBRefDat' 2745 if lowercasetablenames: 2746 tablename=tablename.lower() 2747 tabcol=['Id','SeqBeg','InsBeg','SeqEnd','InsEnd','DBName','DBAccess','DBCode','DBSeqBeg','DBInsBeg','DBSeqEnd','DBInsEnd','ChainIdFk','EntryIdFk']#column names 2748 ################################################################################ 2749 if not self.isMacMolTabDesCorr(tablename,tabcol):#is table description correct 2750 print 'Error, %s: Incorrect table description!'%tablename 2751 self.log.error('%s: Incorrect table description',tablename) 2752 sys.exit(1) 2753 if not kwarg.has_key('anyflag'): 2754 kwarg.setdefault('anyflag',False) 2755 2756 indict={}#input list 2757 ID=kwarg.get('ID',None) 2758 if ID:## ID must be list of length=1 2759 if not isinstance(ID,list) or len(ID)!=1: 2760 print 'Error, %s: Incorrect ID specification!' %tablename 2761 if logdebug: 2762 self.log.debug('%s: Incorrect ID specification',tablename) 2763 return 0 2764 if isinstance(ID[0],(int,long)):#id input ID is integer get ID, if long insert record 2765 EntryIdFk=str(ID[0])#set Molecule foreign key 2766 2767 IDlist=kwarg.get('IDlist',None) 2768 if IDlist:## must be list 2769 if not isinstance(IDlist,list): 2770 print 'Error, %s: Incorrect IDlist specification!' %tablename 2771 if logdebug: 2772 self.log.debug('%s: Incorrect IDlist specification',tablename) 2773 return 0 2774 2775 IDict=kwarg.get('IDict',None) 2776 if IDict:## must be dictionary 2777 if not isinstance(IDict,dict): 2778 print 'Error, %s: Incorrect IDict specification!' %tablename 2779 if logdebug: 2780 self.log.debug('%s: Incorrect IDict specification',tablename) 2781 return 0 2782 select