Skip to content
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

basic guesser features #3753

Open
wants to merge 292 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
292 commits
Select commit Hold shift + click to select a range
2166895
Update DefaultGuesser.py
aya9aladdin Jul 23, 2022
949256d
Update base.py
aya9aladdin Jul 23, 2022
bc0a65a
Update base.py
aya9aladdin Jul 23, 2022
60b24c1
Update core.py
aya9aladdin Jul 23, 2022
ce68bd1
Update core.py
aya9aladdin Jul 23, 2022
ae862fc
Update core.py
aya9aladdin Jul 23, 2022
c5d3453
Merge branch 'develop' into guesser-basics
aya9aladdin Jul 23, 2022
f6053dc
Update core.py
aya9aladdin Jul 23, 2022
bb04030
remove guessing from parser
aya9aladdin Jul 25, 2022
91f0d08
Update universe.py
aya9aladdin Jul 25, 2022
2a013f1
Update universe.py
aya9aladdin Jul 25, 2022
93ffc3f
Update base.py
aya9aladdin Jul 25, 2022
bf41f72
Update core.py
aya9aladdin Jul 25, 2022
9cd3460
Update tables.py
aya9aladdin Jul 25, 2022
ca1f871
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Jul 25, 2022
6d48520
Parsers modification / guess_bond update
aya9aladdin Jul 26, 2022
4f2782f
aa
aya9aladdin Jul 26, 2022
6661c36
plural attr
aya9aladdin Jul 26, 2022
8b0cec5
Update __init__.py
aya9aladdin Jul 27, 2022
5a9ed58
Update __init__.py
aya9aladdin Jul 27, 2022
b28f09a
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Jul 27, 2022
6fe79ac
Merge branch 'develop' into guesser-basics
aya9aladdin Jul 27, 2022
fc4ec30
Rename DefaultGuesser.py to defaultGuesser.py
aya9aladdin Jul 27, 2022
ede16ca
Update DefaultGuesser.py
aya9aladdin Jul 27, 2022
76275a3
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Jul 27, 2022
f7bbbe6
Update package/MDAnalysis/core/universe.py
aya9aladdin Jul 28, 2022
f1a09bb
complete baseGuesser + removing rank + upgrading parts of code accord…
aya9aladdin Aug 1, 2022
4dc0ada
remove assigning atomtypes to names in PDBParser
aya9aladdin Aug 1, 2022
770b4ce
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Aug 1, 2022
2c92aa0
resolve automatic guessing empty universe
aya9aladdin Aug 4, 2022
5125953
Update PQRParser.py
aya9aladdin Aug 4, 2022
b0a0ee2
..
aya9aladdin Aug 4, 2022
c2f1f9a
Update default_guesser.py
aya9aladdin Aug 4, 2022
6b2c4c7
Update universe.py
aya9aladdin Aug 4, 2022
0c9e78d
Update universe.py
aya9aladdin Aug 4, 2022
bf2463f
Update universe.py
aya9aladdin Aug 4, 2022
c159461
Update universe.py
aya9aladdin Aug 4, 2022
2039be7
Update universe.py
aya9aladdin Aug 4, 2022
6b6c07b
Update universe.py
aya9aladdin Aug 4, 2022
2ceeec6
Update universe.py
aya9aladdin Aug 4, 2022
4679c18
modify guess_atoms to resolve errors
aya9aladdin Aug 4, 2022
5f81d3e
Update universe.py
aya9aladdin Aug 4, 2022
60cedfc
Update universe.py
aya9aladdin Aug 4, 2022
a7ea8da
Update universe.py
aya9aladdin Aug 4, 2022
18c86f8
Update universe.py
aya9aladdin Aug 4, 2022
3d996c4
modifying bond guessing to not break default behavior
aya9aladdin Aug 5, 2022
23932ca
update guess angles and dihedrals
aya9aladdin Aug 5, 2022
1d988de
modifying parser checking
aya9aladdin Aug 5, 2022
75e7b81
Update universe.py
aya9aladdin Aug 5, 2022
baa3e0b
Update universe.py
aya9aladdin Aug 5, 2022
54b2a64
Update universe.py
aya9aladdin Aug 5, 2022
c85a593
pep style
aya9aladdin Aug 5, 2022
2bd7fff
Update universe.py
aya9aladdin Aug 5, 2022
81c5382
pep
aya9aladdin Aug 5, 2022
78365bd
pep
aya9aladdin Aug 5, 2022
97a3d6b
pep
aya9aladdin Aug 5, 2022
c796eee
pep
aya9aladdin Aug 5, 2022
63d6fe1
Update universe.py
aya9aladdin Aug 5, 2022
8748515
pep
aya9aladdin Aug 5, 2022
c010d47
pep
aya9aladdin Aug 5, 2022
b6fa523
pep
aya9aladdin Aug 5, 2022
ba3e733
Update default_guesser.py
aya9aladdin Aug 5, 2022
3711962
pep
aya9aladdin Aug 5, 2022
10b8c03
Update tables.py
aya9aladdin Aug 5, 2022
c0f826f
Update tables.py
aya9aladdin Aug 5, 2022
636e4bc
pep
aya9aladdin Aug 5, 2022
752f05e
Update universe.py
aya9aladdin Aug 5, 2022
d0e2a8a
Update universe.py
aya9aladdin Aug 5, 2022
986335e
handeling TXYZParser special behavior of guessing masses from names n…
aya9aladdin Aug 5, 2022
b80edec
Update universe.py
aya9aladdin Aug 6, 2022
438ac52
Update universe.py
aya9aladdin Aug 6, 2022
5d6772c
remove guessed attributes test from parsers
aya9aladdin Aug 6, 2022
0dcca86
remove guessed attributes tests from parsers tests
aya9aladdin Aug 6, 2022
1a74cfd
remove guessed attributes tests from parsers tests
aya9aladdin Aug 6, 2022
eba975c
updating test
aya9aladdin Aug 6, 2022
45f90ef
remove tpr from topology cjecking
aya9aladdin Aug 8, 2022
ca525ad
transfer parser checkpoints to guess_topology_attr
aya9aladdin Aug 17, 2022
05a7623
Update universe.py
aya9aladdin Aug 17, 2022
9318bf2
passing all existing tests
aya9aladdin Aug 17, 2022
0297954
reordering some checkpoints
aya9aladdin Aug 18, 2022
2c88dd0
fix openmm and rdkit tests
aya9aladdin Aug 19, 2022
d1516d0
openmm
aya9aladdin Aug 19, 2022
99c8684
addin guess_topology_attr tests
aya9aladdin Aug 19, 2022
0f4fb3d
modify warning msg
aya9aladdin Aug 19, 2022
0d999f1
adding unit test
aya9aladdin Aug 21, 2022
c6431c0
Update base.py
aya9aladdin Aug 21, 2022
1e4395c
Update base.py
aya9aladdin Aug 21, 2022
23d627b
redirect table import to guesser packagr
aya9aladdin Aug 22, 2022
d77e14f
fix txyz parser checkpoint in guess_masses
aya9aladdin Aug 22, 2022
ba1d392
Update default_guesser.py
aya9aladdin Aug 22, 2022
8aaa305
rename file
aya9aladdin Aug 22, 2022
b120594
adding tests
aya9aladdin Aug 22, 2022
0901cb3
Update test_base.py
aya9aladdin Aug 22, 2022
c9dfa0b
adding universe test
aya9aladdin Aug 22, 2022
72e62f0
unit tests modification
aya9aladdin Aug 22, 2022
d2f0ec6
remove unused error checking
aya9aladdin Aug 22, 2022
3ba87de
adding more tests to pass codcov
aya9aladdin Aug 22, 2022
6a819b9
Delete .coverage.Aya-MacBook.11217.035601
aya9aladdin Aug 22, 2022
f3669df
Update test_encore.py
aya9aladdin Aug 22, 2022
044bc74
add more tests
aya9aladdin Aug 23, 2022
4a821e1
updating some messages
aya9aladdin Aug 26, 2022
ed05187
Update test_openmm_parser.py
aya9aladdin Aug 26, 2022
1032019
update documents
aya9aladdin Aug 26, 2022
7b0041c
Update test_openmm_parser.py
aya9aladdin Aug 26, 2022
2fe59fa
Update test_openmm_parser.py
aya9aladdin Aug 26, 2022
5d6550e
opemmm test
aya9aladdin Aug 27, 2022
6a1e4c5
Update default_guesser.py
aya9aladdin Aug 27, 2022
25aaf73
BaseGuesser documentation
aya9aladdin Aug 27, 2022
501e397
DefaultGuesser documentation
aya9aladdin Aug 27, 2022
d9a65a7
bond guessing + updating guessing API code + minor updates
aya9aladdin Sep 10, 2022
4395f6f
style fixes
aya9aladdin Sep 10, 2022
c234e75
Update universe.py
aya9aladdin Sep 10, 2022
fdb296c
fixing openmm parser message typos
aya9aladdin Sep 10, 2022
c4b200d
Update testsuite/MDAnalysisTests/converters/test_rdkit_parser.py
aya9aladdin Sep 12, 2022
a9b4354
Update testsuite/MDAnalysisTests/guesser/test_default_guesser.py
aya9aladdin Sep 12, 2022
965cd72
Update testsuite/MDAnalysisTests/core/test_universe.py
aya9aladdin Sep 12, 2022
6338a8e
restore table.py default style
aya9aladdin Sep 12, 2022
4324f72
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Sep 12, 2022
17fded8
Merge branch 'develop' into guesser-basics
aya9aladdin Sep 17, 2022
4c29a39
pep styling
aya9aladdin Sep 17, 2022
9fa7b32
Update test_default_guesser.py
aya9aladdin Sep 17, 2022
f450c6f
pep styling
aya9aladdin Sep 17, 2022
f6b9b97
Apply suggestions from code review
aya9aladdin Sep 17, 2022
460d2f5
typos fixing
aya9aladdin Sep 17, 2022
af84927
adding partial guessing + parser tests + noValue topologyattr
aya9aladdin Sep 21, 2022
002e1d6
Merge branch 'develop' into guesser-basics
aya9aladdin Sep 21, 2022
390ae37
Apply suggestions from code review
aya9aladdin Sep 21, 2022
a5c303c
Update base.py
aya9aladdin Sep 21, 2022
b01b092
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Sep 21, 2022
61831f8
Update bat.py
aya9aladdin Sep 21, 2022
7f638fb
Update bat.py
aya9aladdin Sep 21, 2022
cd37c19
Update bat.py
aya9aladdin Sep 21, 2022
71e9a2b
Update bat.py
aya9aladdin Sep 21, 2022
084ab13
removing test skipping
aya9aladdin Sep 21, 2022
fa9128a
Merge branch 'develop' into guesser-basics
aya9aladdin Sep 21, 2022
991070c
update txyz
aya9aladdin Sep 21, 2022
62c43cd
variable names update + partial guessing updates
aya9aladdin Sep 25, 2022
314b31c
Apply suggestions from code review
aya9aladdin Sep 26, 2022
0dcbacd
Adding docstring
aya9aladdin Sep 27, 2022
9a230a4
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Sep 27, 2022
f82bdcf
fix typo in topology tests + add element to ITPParser
aya9aladdin Sep 28, 2022
6f6f634
Added tests for BaseGuesser + updating guess_Attr()
aya9aladdin Sep 30, 2022
40ef1ed
update docstring of guess_attr
aya9aladdin Sep 30, 2022
9222d96
removed parser checking for auto-guessing
aya9aladdin Oct 12, 2022
b712a77
restoring old style
aya9aladdin Oct 12, 2022
8724bba
Apply suggestions from code review
aya9aladdin Oct 12, 2022
0abb069
removing autopep8 effect
aya9aladdin Oct 12, 2022
c1b05ba
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Oct 12, 2022
02d62b1
add comment to bat.py::_sort_atoms_by_mass
aya9aladdin Oct 12, 2022
710df7d
Update OpenMM.py
aya9aladdin Oct 12, 2022
d7cb653
Update universe.py
aya9aladdin Oct 13, 2022
5f6a6f3
passing empty attribute indices for partial guessing
aya9aladdin Oct 14, 2022
f12e5f1
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Oct 14, 2022
d76362b
updating docstring
aya9aladdin Oct 15, 2022
a8ba36c
Merge branch 'MDAnalysis:develop' into guesser-basics
aya9aladdin Oct 15, 2022
49c803c
solve universe unpickle issue
aya9aladdin Oct 15, 2022
f816441
Update test_h5md.py
aya9aladdin Oct 15, 2022
e1347a7
override is_value_missing for Masses class
aya9aladdin Oct 18, 2022
3ebce3f
default guesser pdep8 upates
aya9aladdin Oct 18, 2022
10cad41
pep8 updates
aya9aladdin Oct 18, 2022
626cb39
pep8 updates
aya9aladdin Oct 18, 2022
b476301
remove unrelated analysis module tests
aya9aladdin Oct 18, 2022
3fbdc46
remove line from test_encore.py
aya9aladdin Oct 18, 2022
7b42095
remove autopep8 effect from testpositionaveraging.py
aya9aladdin Oct 19, 2022
21aae8e
Update test_positionaveraging.py
aya9aladdin Oct 19, 2022
3e5a9e9
add guesser tests + pep8 updates
aya9aladdin Oct 19, 2022
98d91fe
restore universe.Merge docstring formatting
aya9aladdin Oct 19, 2022
78654e5
remove autopep8 effect from universe.py
aya9aladdin Oct 19, 2022
a954aee
remove autopep8 effect from universe.py
aya9aladdin Oct 19, 2022
dfb3761
Apply suggestions from code review
aya9aladdin Oct 19, 2022
3df1d9b
removing autopep8 effect from irrelevant parts + adding pep styles
aya9aladdin Oct 19, 2022
e273d68
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Oct 19, 2022
4ad3948
finishing pep8 styling
aya9aladdin Oct 19, 2022
1518729
docstring updates
aya9aladdin Oct 19, 2022
d1e27e3
restore a useful autopep8 change
aya9aladdin Oct 20, 2022
348f62d
add guessing elements from masses to DefaultGuesser
aya9aladdin Oct 20, 2022
e2c03cd
Update test_default_guesser.py
aya9aladdin Oct 20, 2022
ad50c17
added tests to DefaultGuesser and GuesserBasics
aya9aladdin Oct 20, 2022
7663a5b
Update base.py
aya9aladdin Oct 20, 2022
aece5bc
update docstring
aya9aladdin Oct 23, 2022
6175b37
Update topology_modules.rst
aya9aladdin Oct 23, 2022
52fcb41
Merge branch 'develop' into guesser-basics
aya9aladdin Jan 28, 2023
a463561
Revert "Merge branch 'develop' into guesser-basics"
aya9aladdin Jan 28, 2023
d67c921
Revert "Revert "Merge branch 'develop' into guesser-basics""
aya9aladdin Jan 28, 2023
492ccd7
Revert "Revert "Merge branch 'develop' into guesser-basics""
aya9aladdin Jan 29, 2023
f50a7b1
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Jan 29, 2023
3dc7535
silencing guessing processes in some tests
aya9aladdin Feb 20, 2023
2e8d863
silencing guessing process in irrelevant tests
aya9aladdin Feb 25, 2023
a22afc0
style fixations
aya9aladdin Feb 26, 2023
0285dd1
fix styling
aya9aladdin Feb 26, 2023
476444e
style fixations
aya9aladdin Feb 26, 2023
3c3df98
add guesser context + removing styling errors in ITP
aya9aladdin Mar 3, 2023
6be3ec4
Update universe.py
aya9aladdin Mar 3, 2023
7b0ce2e
copy method of Guesser class
aya9aladdin Mar 3, 2023
aaf1d08
Update universe.py
aya9aladdin Mar 3, 2023
1fd7d69
pass universe context to serialisation methods
aya9aladdin Mar 3, 2023
e29d3e6
Update universe.py
aya9aladdin Mar 3, 2023
f64ca1d
update changelog and versionchanged
aya9aladdin Mar 10, 2023
c0ff781
Merge branch 'develop' into guesser-basics
aya9aladdin Mar 10, 2023
58a0d75
docstring error
aya9aladdin Mar 10, 2023
2291a4d
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Mar 10, 2023
21950f6
typo fixing
aya9aladdin Mar 10, 2023
e7c0241
Update CHANGELOG
aya9aladdin Mar 10, 2023
c0ce6e0
Merge branch 'develop' into guesser-basics
aya9aladdin Apr 27, 2023
b776f09
Update groups.py
aya9aladdin Apr 28, 2023
1d8e2cd
Merge branch 'develop' into guesser-basics
aya9aladdin Sep 10, 2023
fc18d4f
updating CHANGELOG + versionchanged doc
aya9aladdin Sep 10, 2023
06211cc
Merge branch 'develop' into guesser-basics
aya9aladdin Sep 12, 2023
240af1c
improving guess_attr + updating changelog
aya9aladdin Sep 12, 2023
ff71b1a
Merge branch 'develop' into guesser-basics
aya9aladdin Sep 17, 2023
2aeb0fc
removed types from FHIAMSParser and XYZParser
aya9aladdin Sep 17, 2023
7580855
Update CHANGELOG
aya9aladdin Sep 17, 2023
202d62a
added DefaultGuesser tests
aya9aladdin Sep 24, 2023
27fcf3b
Merge branch 'develop' into guesser-basics
aya9aladdin Sep 24, 2023
5c5c684
Merge branch 'develop' into guesser-basics
aya9aladdin Nov 6, 2023
5ccd1d1
Update package/CHANGELOG
aya9aladdin Dec 27, 2023
b343d11
Update package/CHANGELOG
aya9aladdin Dec 27, 2023
b3f292d
Merge branch 'develop' into guesser-basics
aya9aladdin Dec 27, 2023
8dc935b
Apply suggestions from code review
aya9aladdin Dec 27, 2023
51c75a6
silencing auto guessing in coordinates tests
aya9aladdin Dec 27, 2023
e1e5b3e
applying @lilyminium suggestions
aya9aladdin Dec 27, 2023
68580ea
applying @lilyminium code review suggesitions
aya9aladdin Jan 6, 2024
6da8ca8
removed guessed_types/masses tests
aya9aladdin Jan 6, 2024
5d505a4
Apply suggestions from code review
aya9aladdin Feb 1, 2024
934d7e6
Merge branch 'develop' into guesser-basics
aya9aladdin Feb 1, 2024
c7ca389
removed guessed_types/masses + unnecessary imports
aya9aladdin Feb 1, 2024
14a6ed2
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Feb 1, 2024
bd12db2
fixed test_itp typo + removed guessed_attrs errors
aya9aladdin Feb 1, 2024
88bb017
Adding more tests
aya9aladdin Feb 1, 2024
40c7632
Merge branch 'develop' into guesser-basics
aya9aladdin Mar 16, 2024
28aeb6a
adding guesser tests
aya9aladdin Mar 16, 2024
da15709
adding tests for DefaultGuesser
aya9aladdin Mar 16, 2024
83ee7f5
adding final tests + styling
aya9aladdin Mar 25, 2024
c67dc3a
Removing old modules + updating CHANGELOG
aya9aladdin Mar 26, 2024
ca43651
Merge branch 'develop' into guesser-basics
aya9aladdin Mar 26, 2024
67ad49e
fix importing error
aya9aladdin Mar 26, 2024
5ee7bae
Merge branch 'guesser-basics' of https://github.com/aya9aladdin/mdana…
aya9aladdin Mar 26, 2024
817cab1
removing guessing part from topology docs
aya9aladdin Mar 26, 2024
6f60435
updating docs
aya9aladdin Mar 30, 2024
a946156
Merge branch 'develop' into guesser-basics
aya9aladdin Mar 31, 2024
ba9deaf
Merge branch 'develop' into guesser-basics
aya9aladdin Apr 17, 2024
fc0ebe6
Apply suggestions from code review
aya9aladdin Apr 21, 2024
4976166
fixing styling
aya9aladdin Apr 26, 2024
77fb208
fixing styling issue + rdkitparser tests
aya9aladdin May 19, 2024
eeaf35a
Apply LAST suggestions from code review
aya9aladdin Sep 17, 2024
80a1b74
Merge branch 'develop' into guesser-basics
aya9aladdin Sep 17, 2024
8986a97
- removed guessing types from masses
aya9aladdin Sep 17, 2024
c0b833e
Update CHANGELOG
aya9aladdin Sep 17, 2024
00dff7c
Update universe.py
aya9aladdin Sep 17, 2024
1c15f21
Merge branch 'develop' into guesser-basics
IAlibay Sep 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions package/MDAnalysis/core/universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
import os
import uuid

from .. import _TOPOLOGY_ATTRS, _PARSERS
from .. import _TOPOLOGY_ATTRS, _PARSERS, _GUESSERS
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
from ..exceptions import NoDataError
from ..lib import util
from ..lib.log import ProgressBar
Expand All @@ -86,8 +86,7 @@
from .topology import Topology
from .topologyattrs import AtomAttr, ResidueAttr, SegmentAttr, BFACTOR_WARNING
from .topologyobjects import TopologyObject


from ..guesser.core import get_guesser
logger = logging.getLogger("MDAnalysis.core.universe")


Expand Down Expand Up @@ -173,7 +172,6 @@ def _generate_from_topology(universe):
universe.segments = SegmentGroup(
np.arange(universe._topology.n_segments), universe)


class Universe(object):
"""The MDAnalysis Universe contains all the information describing the system.

Expand Down Expand Up @@ -316,7 +314,8 @@ class Universe(object):
"""
def __init__(self, topology=None, *coordinates, all_coordinates=False,
format=None, topology_format=None, transformations=None,
guess_bonds=False, vdwradii=None, in_memory=False,
guess_bonds=False, vdwradii=None, context='default',
to_guess=[], in_memory=False,
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
in_memory_step=1, **kwargs):

self._trajectory = None # managed attribute holding Reader
Expand All @@ -328,6 +327,8 @@ def __init__(self, topology=None, *coordinates, all_coordinates=False,

self._kwargs = {
'transformations': transformations,
'context': context,
'to_guess': to_guess,
'guess_bonds': guess_bonds,
'vdwradii': vdwradii,
'in_memory': in_memory,
Expand Down Expand Up @@ -373,6 +374,8 @@ def __init__(self, topology=None, *coordinates, all_coordinates=False,
if guess_bonds:
self.atoms.guess_bonds(vdwradii=vdwradii)

self.guess_topoloyAttribute(context, to_guess)

def copy(self):
"""Return an independent copy of this Universe"""
new = self.__class__(self._topology.copy())
Expand Down Expand Up @@ -1436,6 +1439,19 @@ def from_smiles(cls, smiles, sanitize=True, addHs=True,

return cls(mol, **kwargs)

def guess_topoloyAttribute(self, context, to_guess):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def guess_topoloyAttribute(self, context, to_guess):
def guess_TopologyAttr(self, context, to_guess):

There's already a method called add_TopologyAttr, and the class is called a TopologyAttr. Going with the principal of least astonishment that advises a consistent API, could you please rename this method to something that users could easily guess (😛) themselves?

"""guess attributes passed to the universe within specific context

Parameters
----------
context: string or Guesser class
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context: string or Guesser class
context: str or Guesser class

to_guess: list of atrributes to be guessed then added to the universe
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
"""
self._guesser = get_guesser(self.atoms, context)
if self._guesser.is_guessed(to_guess):
for attr in to_guess:
values = self._guesser.guessTopologyAttribute(attr)
self.add_TopologyAttr(attr, values)

def Merge(*args):
jbarnoud marked this conversation as resolved.
Show resolved Hide resolved
"""Create a new new :class:`Universe` from one or more
Expand Down
79 changes: 79 additions & 0 deletions package/MDAnalysis/guesser/DefaultGuesser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from .base import GuesserBase
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
import numpy as np
import warnings
from . import tables


class DefaultGuesser(GuesserBase):
context = 'default'

def __init__(self):
self._guess = {'mass': self.guess_masses}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Instead of this, would it be tidier to have a class-level _guess dictionary like TopologyAttr.transplants? I'm not sure it makes sense for instances of guesser classes to differ.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check this and see how I could integrate the transplant idea


def guess_masses(self):
"""Guess the mass of many atoms based upon their type

Returns
-------
atom_masses : np.ndarray dtype float64
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
"""
atom_types = self._atoms.types
self.validate_atom_types(atom_types)
masses = np.array([self.get_atom_mass(atom_t)
for atom_t in atom_types], dtype=np.float64)
return masses

def validate_atom_types(self, atom_types):
"""Vaildates the atom types based on whether they are available
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
in our tables

Parameters
----------
atom_types
Type of each atom

Returns
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
-------
None

.. versionchanged:: 0.20.0
Try uppercase atom type name as well
"""
for atom_type in np.unique(atom_types):
try:
tables.masses[atom_type]
except KeyError:
try:
tables.masses[atom_type.upper()]
except KeyError:
warnings.warn
("Failed to guess the mass for the following atoms: {}"
.format(atom_type))

def get_atom_mass(self, element):
"""Return the atomic mass in u for *element*.

Masses are looked up in :data:`MDAnalysis.topology.tables.masses`.

.. Warning:: Unknown masses are set to 0.0

.. versionchanged:: 0.20.0
Try uppercase atom type name as well
"""
try:
return tables.masses[element]
except KeyError:
try:
return tables.masses[element.upper()]
except KeyError:
return 0.0

def guess_atom_mass(self, atomname):
"""Guess a mass based on the atom name.

:func:`guess_atom_element` is used to determine the kind of atom.

.. warning:: Anything not recognized is simply set to 0;
if you rely on the masses you might want to double check.
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
"""
return self.get_atom_mass(self.guess_atom_element(atomname))
23 changes: 23 additions & 0 deletions package/MDAnalysis/guesser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- 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
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
#
# 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
#
from . import DefaultGuesser
48 changes: 48 additions & 0 deletions package/MDAnalysis/guesser/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class GuesserBase:
context = "base"
_guess = {}

def is_guessed(self, to_guess):
"""check that the passed atrributes in the to_guess
list can be guessed by the class

Parameters
----------
to_guess: list of atrributes to be guessed then added to the universe
Returns
-------
True or False
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
"""
for a in to_guess:
if a.lower() not in self._guess:
raise ValueError('{0} guesser can not guess the {1} atrribute'
.format(self.context, a))
return True

def guessTopologyAttribute(self, to_guess):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the absence of type hinting, could you please change the name of the to_guess variables to be clearer? here it's one string, but in is_guessed it's a list of strings -- that is quite confusing. Also, could you please name your methods with conventional snake_case and use TopologyAttr instead of TopologyAttribute?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan to have an overall method for guessing all the attributes at once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'm planning to have a method for guessing all the attributes at once, this was just a test for guessing one attribute

"""map the attribute to be guessed with the apporpiate guessing method

Parameters
----------
to_guess: an atrribute to be guessed then added to the universe

Returns
-------
values: list of guessed values
"""
values = self._guess[to_guess]()
return values

def setAtoms(self, atoms):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this method need to exist? Could __init__ just take atoms instead, like a Writer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember why I did it this way tbh, so I'll remove it

"""get the AtomGroup of the universe to use its attributes
inside the guessing methods

Parameters
----------
atoms: AtomGroup of the universe

Returns
-------
values: list of guessed values
"""
self._atoms = atoms
29 changes: 29 additions & 0 deletions package/MDAnalysis/guesser/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

from .base import GuesserBase
from .DefaultGuesser import DefaultGuesser

# guessers dictionary mimic registaration by metaclass
GUESSERS = {'DEFAULT': DefaultGuesser}


def get_guesser(atoms, context):
"""get an appropiate guesser to the universe and pass
the atomGroup of the universe to the guesser

Parameters
----------
atoms: AtomGroup of the universe
context: string or Guesser class
Returns
-------
TGuesser class
"""
if isinstance(context, GuesserBase):
context.setAtoms(atoms)
return context
try:
guesser = GUESSERS[context.upper()]
guesser.setAtoms(atoms)
except KeyError:
raise TypeError("Unidentified guesser type {0}".format(context))
return guesser
Loading