Skip to content

Setting attributes should have dtype checks #2764

@richardjgowers

Description

@richardjgowers

Our Topology system is statically typed, each TopologyAttr (found here) should only accept one data type, e.g. atom names (here) should always be strings, resids should always be ints.

Currently setting an atom name to an integer gives "TypeError: 'int' object is not iterable"

import MDAnalysis as mda

u = mda.fetch_mmft('181l')

u.atoms[0].name = 1

This should instead fail and inform that atom names need to be strings.

Setting a Residue's resid to a float seems to work...

import MDAnalysis as mda

u = mda.fetch_mmft('181l')

u.residues[0].resid = 2.4

This probably is using the inbuilt rounding in numpy int arrays, but it should probably raise an error too.

To fix this, we could have a check_dtype decorator around TopologyAttr.set_atoms (and residue/segment) to check that the supplied values are the correct type.

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