-
Notifications
You must be signed in to change notification settings - Fork 667
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cédric Bouysset
authored
Jun 19, 2020
1 parent
788f294
commit 50cd6e7
Showing
18 changed files
with
990 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- | ||
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
# | ||
# MDAnalysis --- https://www.mdanalysis.org | ||
# Copyright (c) 2006-2017 The MDAnalysis Development Team and contributors | ||
# (see the file AUTHORS for the full list of names) | ||
# | ||
# Released under the GNU Public Licence, v2 or any higher version | ||
# | ||
# Please cite your use of MDAnalysis in published work: | ||
# | ||
# R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler, | ||
# D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein. | ||
# MDAnalysis: A Python package for the rapid analysis of molecular dynamics | ||
# simulations. In S. Benthall and S. Rostrup editors, Proceedings of the 15th | ||
# Python in Science Conference, pages 102-109, Austin, TX, 2016. SciPy. | ||
# doi: 10.25080/majora-629e541a-00e | ||
# | ||
# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein. | ||
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. | ||
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 | ||
# | ||
|
||
"""RDKit molecule --- :mod:`MDAnalysis.coordinates.RDKit` | ||
================================================================ | ||
Read coordinates data from an `RDKit <https://www.rdkit.org/docs/source/rdkit.Chem.rdchem.html#rdkit.Chem.rdchem.Mol>`_ :class:`rdkit.Chem.rdchem.Mol` with :class:`RDKitReader` | ||
into a MDAnalysis Universe. Convert it back to a :class:`rdkit.Chem.rdchem.Mol` with | ||
:class:`RDKitConverter`. | ||
Example | ||
------- | ||
>>> from rdkit import Chem | ||
>>> import MDAnalysis as mda | ||
>>> mol = Chem.MolFromMol2File("docking_poses.mol2", removeHs=False) | ||
>>> u = mda.Universe(mol) | ||
>>> u | ||
<Universe with 42 atoms> | ||
>>> u.trajectory | ||
<RDKitReader with 10 frames of 42 atoms> | ||
Classes | ||
------- | ||
.. autoclass:: RDKitReader | ||
:members: | ||
.. autoclass:: RDKitConverter | ||
:members: | ||
""" | ||
|
||
import warnings | ||
|
||
import numpy as np | ||
|
||
from . import memory | ||
|
||
|
||
class RDKitReader(memory.MemoryReader): | ||
"""Coordinate reader for RDKit. | ||
.. versionadded:: 2.0.0 | ||
""" | ||
format = 'RDKIT' | ||
|
||
# Structure.coordinates always in Angstrom | ||
units = {'time': None, 'length': 'Angstrom'} | ||
|
||
@staticmethod | ||
def _format_hint(thing): | ||
"""Can this reader read *thing*?""" | ||
try: | ||
from rdkit import Chem | ||
except ImportError: | ||
# if we can't import rdkit, it's probably not rdkit | ||
return False | ||
else: | ||
return isinstance(thing, Chem.Mol) | ||
|
||
def __init__(self, filename, **kwargs): | ||
"""Read coordinates from an RDKit molecule. | ||
Each conformer in the original RDKit molecule will be read as a frame | ||
in the resulting universe. | ||
Parameters | ||
---------- | ||
filename : rdkit.Chem.rdchem.Mol | ||
RDKit molecule | ||
""" | ||
n_atoms = filename.GetNumAtoms() | ||
coordinates = np.array([ | ||
conf.GetPositions() for conf in filename.GetConformers()], | ||
dtype=np.float32) | ||
if coordinates.size == 0: | ||
warnings.warn("No coordinates found in the RDKit molecule") | ||
coordinates = np.empty((1,n_atoms,3), dtype=np.float32) | ||
coordinates[:] = np.nan | ||
super(RDKitReader, self).__init__(coordinates, order='fac', **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.