Skip to content

Commit

Permalink
Merge branch 'develop' into fix-bond-deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
IAlibay authored Oct 25, 2024
2 parents 367e2c4 + d7153b9 commit 560ad70
Show file tree
Hide file tree
Showing 15 changed files with 922 additions and 11 deletions.
6 changes: 6 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Fixes
* Fixes bug where multiple identical connection topologies could be
added to a _Connection TopologyAttr, and that deleting connections
by index would only delete one of them (Issue #4762, PR #4763)
* Changes error to warning on Universe creation if guessing fails
due to missing information (Issue #4750, PR #4754)
* Adds guessed attributes documentation back to each parser page
and updates overall guesser docs (Issue #4696)
* Fix Bohrium (Bh) atomic mass in tables.py (PR #3753)
Expand Down Expand Up @@ -115,6 +117,10 @@ Changes
numpy.testing.assert_allclose #4438)

Deprecations
* MDAnalysis.topology.guessers is deprecated in favour of the new
Guessers API and will be removed in version 3.0 (PR #4752)
* MDAnalysis.topology.tables is deprecated in favour of
MDAnalysis.guesser.tables and will be removed in version 3.0 (PR #4752)
* Element guessing in the ITPParser is deprecated and will be removed in version 3.0
(Issue #4698)
* Unknown masses are set to 0.0 for current version, this will be depracated
Expand Down
29 changes: 25 additions & 4 deletions package/MDAnalysis/core/universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ def __init__(self, topology=None, *coordinates, all_coordinates=False,
force_guess = list(force_guess) + ['bonds', 'angles', 'dihedrals']

self.guess_TopologyAttrs(
context, to_guess, force_guess, vdwradii=vdwradii, **kwargs)
context, to_guess, force_guess, error_if_missing=False
)


def copy(self):
Expand Down Expand Up @@ -1498,7 +1499,9 @@ def from_smiles(cls, smiles, sanitize=True, addHs=True,
return cls(mol, **kwargs)

def guess_TopologyAttrs(
self, context=None, to_guess=None, force_guess=None, **kwargs):
self, context=None, to_guess=None, force_guess=None,
error_if_missing=True, **kwargs
):
"""
Guess and add attributes through a specific context-aware guesser.
Expand All @@ -1523,6 +1526,13 @@ def guess_TopologyAttrs(
TopologyAttr does not already exist in the Universe, this has no
effect. If the TopologyAttr does already exist, all values will
be overwritten by guessed values.
error_if_missing: bool
If `True`, raise an error if the guesser cannot guess the attribute
due to missing TopologyAttrs used as the inputs for guessing.
If `False`, a warning will be raised instead.
Errors will always be raised if an attribute is in the
``force_guess`` list, even if this parameter is set to False.
**kwargs: extra arguments to be passed to the guesser class
Examples
Expand All @@ -1537,7 +1547,11 @@ def guess_TopologyAttrs(
if not context:
context = self._context

guesser = get_guesser(context, self.universe, **kwargs)
# update iteratively to avoid multiple kwargs clashing
guesser_kwargs = {}
guesser_kwargs.update(self._kwargs)
guesser_kwargs.update(kwargs)
guesser = get_guesser(context, self.universe, **guesser_kwargs)
self._context = guesser

if to_guess is None:
Expand Down Expand Up @@ -1577,7 +1591,14 @@ def guess_TopologyAttrs(
for attr in total_guess:
if guesser.is_guessable(attr):
fg = attr in force_guess
values = guesser.guess_attr(attr, fg)
try:
values = guesser.guess_attr(attr, fg)
except ValueError as e:
if error_if_missing or fg:
raise e
else:
warnings.warn(str(e))
continue

if values is not None:
if attr in objects:
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/guesser/default_guesser.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def guess_types(self, atom_types=None, indices_to_guess=None):
atom_types = self._universe.atoms.names
except AttributeError:
raise ValueError(
"there is no reference attributes in this universe"
"there is no reference attributes in this universe "
"to guess types from")

if indices_to_guess is not None:
Expand Down
Loading

0 comments on commit 560ad70

Please sign in to comment.