-
Notifications
You must be signed in to change notification settings - Fork 826
RDKitReader and RDKitParser #2707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
ba1f3e4
barebones topology from RDKitParser
7e172fc
test for PDB and MOL2 + fix atomtypes and residues
c436517
fix test on bond orders
b25898f
add SMILES parser test
60af718
reorganize code + create name if not present
94f18b5
added Segids attribute
fdb6513
added rdkit to appveyor and travis
9caaa5c
added SDF file for rdkit tests
88b2130
forgot hydrogens and 3D on SDFile
ffbf149
SDF test
8736750
added formal charges + attrs specific to PDB files
db73687
fix charges to partial instead of formal
29a3e8e
Merge branch 'develop' into develop
94f1e4d
added warning if multiple partial charges
b60a50e
updated parser doc
73342e2
universe.from_smiles + tests on MOL2 charges
4baae68
universe from smiles generate coordinates and tests + doc
bf5ee1a
renamed n_frames to numConfs to be in line with RDKit
ecc53b1
bond order testing from rdkit
396da83
added aromaticity attr
6540260
coordinates reader
d18bb12
added tests on coordinates
0c8dcc4
aromatic atomselection + test
d9dd747
fix minimal dependency
b75297c
updated docs
9aafc6a
updated doc
77617d2
fix PEP8 and init array
d6d7fe3
test combine aromatic selection
dc7ec77
test compare with mol2reader
18dc450
added kwargs for EmbedMultipleConfs
0c891f4
example for EmbedMultipleConfs kwargs
eac10ab
warning and tests on coordinates
60ab691
Merge branch 'develop' into develop
5cad0ba
drop python 2 support
e0e99ad
Merge branch 'develop' of https://github.com/cbouy/mdanalysis into de…
3ab5658
modified tests
0aff0f6
fix using fixtures in parametrize
f0497bf
actual fix for coordinate tests
2755853
fix the docs and style guide
b611915
update docs and changelog for 2.0.0
dc48240
Merge branch 'develop' into develop
76fb209
Update selection.py
richardjgowers 13168ba
Update selection.py
richardjgowers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -568,6 +568,21 @@ class AltlocSelection(StringSelection): | |
| field = 'altLocs' | ||
|
|
||
|
|
||
| class AromaticSelection(Selection): | ||
cbouy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Select aromatic atoms. | ||
|
|
||
| Aromaticity is available in the `aromaticities` attribute and is made | ||
| available through RDKit""" | ||
| token = 'aromatic' | ||
| field = 'aromaticities' | ||
|
|
||
| def __init__(self, parser, tokens): | ||
| pass | ||
|
|
||
| def apply(self, group): | ||
| return group[group.aromaticities].unique | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed this so that it will fail if there aren't aromaticities available, rather than silently putting everything as false |
||
|
|
||
|
|
||
| class ResidSelection(Selection): | ||
| """Select atoms based on numerical fields | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this happen when the Mol has no coordinates? Worth raising a warning at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and since the memory reader expects a numpy array I thought it would be best to have it at least with the right shape
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a feeling for what the standard behaviour across the MDA readers is? I believe the netcdf reader will just throw an error if it can't find a reasonable dimension (my thought here is that we would want to have a similar behaviour to how other things work).