id = id.strip('\n') molecule.add(id) molecule.commit() # download ligand structures def save(id, s, format, dir): filename = '{}/{}.{}'.format(dir, id, format) with open(filename, 'w') as file: file.write(s) print(id) structure_dir = project_dir + '/data/structure/ligand' molecule.foreachStructure( lambda id, s, format: save(id, s, format, structure_dir)) print('convert to pdb') def convert(id, dir, fromformat, toformat): org = '{}/{}.{}'.format(dir, id, fromformat) dst = '{}/{}.{}'.format(dir, id, toformat) os.system('obabel -i{} {} -o{} > {}'.format(fromformat, org, toformat, dst)) os.system('rm ' + org) print(id) molecule.foreach(lambda data: convert(data[1][1], structure_dir, 'sdf', 'pdb'))
def instage(id, pt): return pt.filename('{}.pdb'.format(id), pt.stage, '*.pdb') != None def copy(id, dir, pt, pids): try: stagefile = pt.filename('{}.pdb'.format(id), pt.stage, '*.pdb') os.system('cp {} {}/{}.pdb'.format(stagefile, dir, id.upper())) print('!', 'stage: ', id, sep='\t') except: print('?', 'stage: ', id, sep='\t') pids.append(id) def save(id, s, format, dir): filename = '{}/{}.{}'.format(dir, id, format) with open(filename, 'w') as file: file.write(s) print(id) structure_dir = project_dir + '/data/structure/ligand' pids = [] molecule.foreachStructure( lambda id, s, format: save(id, s, format, structure_dir), lambda id: not instage(id, pt), lambda id: copy(str(id), structure_dir, pt, pids)) molecule.close()