Download utils/molecules_utils.py from SuChi0507/DiffDock: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/SuChi0507/DiffDock/resolve/main/utils/molecules_utils.py
- Command line
-
hf download hf://SuChi0507/DiffDock/utils/molecules_utils.py
-
curl -L -o molecules_utils.py https://huggingface.co/SuChi0507/DiffDock/resolve/main/utils/molecules_utils.py
1.09 kB
| from spyrmsd import rmsd, molecule | |
| def get_symmetry_rmsd(mol, coords1, coords2, mol2=None, return_permutation=False): | |
| with time_limit(10): | |
| mol = molecule.Molecule.from_rdkit(mol) | |
| mol2 = molecule.Molecule.from_rdkit(mol2) if mol2 is not None else mol2 | |
| mol2_atomicnums = mol2.atomicnums if mol2 is not None else mol.atomicnums | |
| mol2_adjacency_matrix = mol2.adjacency_matrix if mol2 is not None else mol.adjacency_matrix | |
| RMSD = rmsd.symmrmsd( | |
| coords1, | |
| coords2, | |
| mol.atomicnums, | |
| mol2_atomicnums, | |
| mol.adjacency_matrix, | |
| mol2_adjacency_matrix, | |
| return_permutation=return_permutation | |
| ) | |
| return RMSD | |
| import signal | |
| from contextlib import contextmanager | |
| class TimeoutException(Exception): pass | |
| def time_limit(seconds): | |
| def signal_handler(signum, frame): | |
| raise TimeoutException("Timed out!") | |
| signal.signal(signal.SIGALRM, signal_handler) | |
| signal.alarm(seconds) | |
| try: | |
| yield | |
| finally: | |
| signal.alarm(0) | |