Skip to content

👌 PseudoPotentialData: Improve string representation#197

Merged
mbercx merged 1 commit intomainfrom
imp/pseudo-description
Sep 23, 2025
Merged

👌 PseudoPotentialData: Improve string representation#197
mbercx merged 1 commit intomainfrom
imp/pseudo-description

Conversation

@mbercx
Copy link
Copy Markdown
Member

@mbercx mbercx commented Sep 23, 2025

The PseudoPotentialData is currently missing a get_description method, which means this returns the default empty string derived from the Node class. The default __repr__ method also does not show one of the most important attributes of the PseudoPotentialData class: the element it represents.

Here we add the __repr__ and get_description methods to the PseudoPotentialData class. Although these could (and perhaps should) serve a different purpose, we don't want users to be confused when they see a difference between:

  • the pseudos dictionary returned by builder.pseudos, which uses __repr__.
  • The __repr_pretty__ method of the ProcessBuilder, which uses get_description for Node objects.

Hence, we make them return the same output by having the get_description method call repr. For the contents, we choose to add:

  • The class name, so they can see the type of pseudopotential.
  • The element of the pseudopotential.
  • The PK of the pseudpotential node.

We skip the UUID to reduce the noise. In most local usage the PK is much more common, and the user can still easily get the UUID using node.uuid.

The `PseudoPotentialData` is currently missing a `get_description` method, which means
this returns the default empty string derived from the `Node` class. The default
`__repr__` method also does not show one of the most important attributes of the
`PseudoPotentialData` class: the element it represents.

Here we add the `__repr__` and `get_description` methods to the `PseudoPotentialData`
class. Although these could (and perhaps should) serve a different purpose, we don't
want users to be confused when they see a difference between:

* the pseudos dictionary returned by `builder.pseudos`, which uses `__repr__`.
* The `__repr_pretty__` method of the `ProcessBuilder`, which uses `get_description`
  for `Node` objects.

Hence, we make them return the same output by having the `get_description` method
call `repr`. For the contents, we choose to add:

* The class name, so they can see the type of pseudopotential.
* The element of the pseudopotential.
* The PK of the pseudpotential node.

We skip the UUID to reduce the noise. In most local usage the PK is much more common,
and the user can still easily get the UUID using `node.uuid`.
@mbercx
Copy link
Copy Markdown
Member Author

mbercx commented Sep 23, 2025

Example usage from aiida-quantumespresso:

from aiida import orm, load_profile 

load_profile()

from ase.build import bulk
from aiida_quantumespresso.calculations.pw import PwCalculation

structure = orm.StructureData(ase=bulk('Si', 'fcc', 5.43))
pseudo_family = orm.load_group('SSSP/1.3/PBEsol/efficiency')

builder = PwCalculation.get_builder()
builder.pseudos = pseudo_family.get_pseudos(structure=structure)
builder

returns

Process class: PwCalculation
Inputs:
metadata:
  options:
    stash: {}
    unstash: {}
monitors: {}
pseudos:
  Si: '<UpfData[Si] (pk: 72)>'

Note that I also adapt the __repr__, so

builder.pseudos

returns

{'Si': <UpfData[Si] (pk: 72)>}

Copy link
Copy Markdown
Collaborator

@t-reents t-reents left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope I have the permissions 😄

Thanks for quickly fixing it, I think that this is indeed very useful for users (especially new ones).

@t-reents
Copy link
Copy Markdown
Collaborator

I hope I have the permissions 😄

Damn, I don't. Sorry @mbercx for not being helpful 😄

@mbercx
Copy link
Copy Markdown
Member Author

mbercx commented Sep 23, 2025

Check your inbox 😉

@t-reents
Copy link
Copy Markdown
Collaborator

Worked

@mbercx mbercx merged commit 2098a1b into main Sep 23, 2025
13 checks passed
@mbercx mbercx deleted the imp/pseudo-description branch September 23, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants