Skip to content

make guessers more consistent and transparent #2348

@orbeckst

Description

@orbeckst

Expected behavior

  • Code should only guess when authorized by the user (see Print warning when a property is guessed  #2222 ).
  • If property cannot be guessed (atom types, bonds, masses) then a proper error message or warning should alert the user and suggest how to enable guessing.
  • Users should be able to override guesses.
  • Guessers should use the best available approach.

Actual behavior

Existing discussions

Code to reproduce the behavior

Example for bad mass guessing from atom_types

import MDAnalysis as mda
from MDAnalysis.tests import datafiles
import numpy as np

u = mda.Universe(datafiles.PDBQT_input)

not_guessed = u.atoms[u.atoms.masses == 0]
print("Missing masses: {}/{}".format(not_guessed.n_atoms, u.atoms.n_atoms))
print("Types without masses:", set(not_guessed.types))

# guessing by name finds all masses
masses_from_name = np.array([mda.topology.guessers.guess_atom_mass(name) for name in not_guessed.names])
print("Guessed masses from missing with name: {}/{}".format(sum(masses_from_name != 0), not_guessed.n_atoms))

# even guessing again from the types improves
masses_from_types_again = np.array([mda.topology.guessers.guess_atom_mass(atype) for atype in not_guessed.types])
print("Guessed masses (again) from missing with type: {}/{}".format(sum(masses_from_types_again != 0), not_guessed.n_atoms))
print("Types without masses:", set(not_guessed[masses_from_types_again == 0].types))

gives

~/anaconda3/envs/mda3/lib/python3.6/site-packages/MDAnalysis/topology/guessers.py:80: UserWarning: Failed to guess the mass for the following atom types: A
  warnings.warn("Failed to guess the mass for the following atom types: {}".format(atom_type))
~/anaconda3/envs/mda3/lib/python3.6/site-packages/MDAnalysis/topology/guessers.py:80: UserWarning: Failed to guess the mass for the following atom types: HD
  warnings.warn("Failed to guess the mass for the following atom types: {}".format(atom_type))
~/anaconda3/envs/mda3/lib/python3.6/site-packages/MDAnalysis/topology/guessers.py:80: UserWarning: Failed to guess the mass for the following atom types: OA
  warnings.warn("Failed to guess the mass for the following atom types: {}".format(atom_type))
Missing masses: 726/1805
Types without masses: {'HD', 'OA', 'A'}
Guessed masses from missing with name: 726/726
Guessed masses (again) from missing with type: 580/726
Types without masses: {'A'}

I actually don't understand why on parsing the topology, the types HD, OA, and A cannot be used for guessing the mass but later HD and OA work and only A fails:

u = mda.Universe(datafiles.PDBQT_input)
ng = np.array([mda.topology.guessers.guess_atom_mass(atype) for atype in u.atoms.types]) == 0
print("No masses for types ", set(u.atoms[ng].types))

Again, warnings as above, but then No masses for types {'A'} only.

Currently version of MDAnalysis

0.20.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions