| 16 | os.makedirs(CACHE_DIR) |
| 17 | |
| 18 | def tm_score(chain1: Peptide, chain2: Peptide): |
| 19 | io, paths = PDBIO(), [] |
| 20 | for i, chain in enumerate([chain1, chain2]): |
| 21 | chain_name = f'{time.time()}_{chain.get_id()}_{chain.seq[:20]}' # for concurrent conflicts |
| 22 | path = os.path.join(CACHE_DIR, f'{chain_name}.pdb') |
| 23 | paths.append(path) |
| 24 | chain = chain.to_bio() |
| 25 | io.set_structure(chain) |
| 26 | io.save(path) |
| 27 | p = os.popen(f'{TMEXEC} {paths[0]} {paths[1]}') |
| 28 | text = p.read() |
| 29 | p.close() |
| 30 | res = re.search(r'TM-score\s*= ([0-1]\.[0-9]+)', text) |
| 31 | score = float(res.group(1)) |
| 32 | for path in paths: |
| 33 | os.remove(path) |
| 34 | return score |