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

Merged
merged 295 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
295 commits
Select commit Hold shift + click to select a range
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
7cc0341
Update package/CHANGELOG
IAlibay Oct 17, 2024
c225f75
Merge remote-tracking branch 'upstream/develop' into guesser-basics
lilyminium Oct 19, 2024
e7ddaaf
Merge branch 'develop' into guesser-basics
lilyminium Oct 19, 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
40 changes: 34 additions & 6 deletions package/MDAnalysis/core/universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import warnings
import contextlib
import collections

import MDAnalysis
import sys

Expand All @@ -72,7 +71,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 +85,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 +171,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 +313,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 +326,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 @@ -372,6 +372,13 @@ def __init__(self, topology=None, *coordinates, all_coordinates=False,

if guess_bonds:
self.atoms.guess_bonds(vdwradii=vdwradii)
# add mass and type to the to_guess list
toplist = list(self._topology.read_attributes)
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
if not any(att.singular == 'type' for att in toplist) and 'type' not in to_guess:
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
to_guess.append('type')
if not any(att.singular == 'mass' for att in toplist) and 'mass' not in to_guess:
to_guess.append('mass')
self.guess_TopologyAttr(context, to_guess)

def copy(self):
"""Return an independent copy of this Universe"""
Expand Down Expand Up @@ -1436,6 +1443,27 @@ def from_smiles(cls, smiles, sanitize=True, addHs=True,

return cls(mol, **kwargs)

def guess_TopologyAttr(self, context, to_guess):
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
"""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):
# sort attributes
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
to_guess = self._guesser.rank_attributes(to_guess)
# check if the attribute already have been read from topology file
toplist = list(self._topology.read_attributes)
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
for attr in to_guess:
if any(attr == a.singular for a in toplist):
warnings.warn('The atrribute {} have already been read '
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
'from the topology file, you are overwriting'
'it by guessed values'.format(attr))
values = self._guesser.guess_topologyAttr(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
155 changes: 155 additions & 0 deletions package/MDAnalysis/guesser/DefaultGuesser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
from .base import GuesserBase
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
import numpy as np
import warnings

import re

from ..lib import distances
from . import tables


class DefaultGuesser(GuesserBase):
context = 'default'

def __init__(self, atoms):
super().__init__(atoms)
self._guess = {'mass': self.guess_masses,
'type': self.guess_types}
self._rank = {'mass': 2,
'type': 1
}

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
"""
if hasattr(self._atoms, 'elements'):
atom_types = self._atoms.elements
else:
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))

def guess_types(self):
"""Guess the atom type of many atoms based on atom name

Parameters
----------
atom_names
Name of each atom

Returns
-------
atom_types : np.ndarray dtype object
"""
names = self._atoms.names
return
np.array([self.guess_atom_element(n) for n in names], dtype=object)

NUMBERS = re.compile(r'[0-9]') # match numbers
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved
SYMBOLS = re.compile(r'[*+-]') # match *, +, -

def guess_atom_element(self, atomname):
"""Guess the element of the atom from the name.

Looks in dict to see if element is found, otherwise it uses the first
character in the atomname. The table comes from CHARMM and AMBER atom
types, where the first character is not sufficient to determine the
atom type. Some GROMOS ions have also been added.

.. Warning: The translation table is incomplete.
This will probably result in some mistakes,
but it still bbetter than nothing!
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved

See Also
--------
:func:`guess_atom_type`
:mod:`MDAnalysis.topology.tables`
"""
if atomname == '':
return ''
try:
return tables.atomelements[atomname.upper()]
except KeyError:
# strip symbols and numbers
no_symbols = re.sub(self.SYMBOLS, '', atomname)
name = re.sub(self.NUMBERS, '', no_symbols).upper()

# just in case
if name in tables.atomelements:
return tables.atomelements[name]

while name:
if name in tables.elements:
return name
if name[:-1] in tables.elements:
return name[:-1]
if name[1:] in tables.elements:
return name[1:]
if len(name) <= 2:
return name[0]
name = name[:-1] # probably element is on left not right

# if it's numbers
return no_symbols
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
59 changes: 59 additions & 0 deletions package/MDAnalysis/guesser/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class GuesserBase:
context = "base"
_guess = {}

# give a rank to each atrribute based on its dependency on other attributes
# to be guessed, so that the attribute with lesser dependcy will be guessed
# first
_rank = {}
aya9aladdin marked this conversation as resolved.
Show resolved Hide resolved

def __init__(self, atoms):
self._atoms = atoms

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 ValueError
"""
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 guess_topologyAttr(self, guess):
"""map the attribute to be guessed with the apporpiate guessing method

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

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

def rank_attributes(self, attrs):
"""give a rank to each atrribute based on
its dependency on other attributes to be guessed,
so that the attribute with lesser dependcy will
be guessed first

Parameters
----------
attrs: attributes list to be sorted

Returns
-------
sorted attributes list
"""
to_rank = {a: self._rank[a] for a in attrs}
ranked_attrs = sorted(to_rank, key=to_rank.get)
return ranked_attrs
27 changes: 27 additions & 0 deletions package/MDAnalysis/guesser/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

from .base import GuesserBase
from .DefaultGuesser import DefaultGuesser

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


def get_guesser(a, 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
-------
Guesser class
"""
if isinstance(context, GuesserBase):
return context
try:
guesser = GUESSERS[context.upper()](a)
except KeyError:
raise TypeError("Unidentified guesser type {0}".format(context))
return guesser
Loading