Skip to content

Adding attributes to Atom class #1

Open
@pcpatfire

Description

@pcpatfire

Hi,
I need to add some more attributes to the Atom class. How can I do it, without changing your Atom and Structures classes?
For instance, I need to add the atomic mass information. I was using settattr to add it to each Atom instance, as follows:

for i in range(atom_num):
    # some code here...
    setattr(atoms[i], 'mass', mass_value)

s = Structure(atoms, lattice=lattice, title=title)

This solution is partially working, because the information is saved in the Atom instance, and I can get it as, for instance, s[5].mass (where 5 is the index of the 6th atom in the list), but s[5:7].mass generates the following error:

AttributeError: 'Structure' object has no attribute 'mass'

Is there a better to fix this issue?
Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions