Skip to content

Custom definition of properties in the scripting module#494

Merged
ceriottm merged 6 commits intomainfrom
scripting/properties
Feb 12, 2026
Merged

Custom definition of properties in the scripting module#494
ceriottm merged 6 commits intomainfrom
scripting/properties

Conversation

@ceriottm
Copy link
Copy Markdown
Contributor

@ceriottm ceriottm commented Feb 5, 2026

This allows defining new properties, that can then be computed and output with the usual i-PI output mechanism.

@ceriottm ceriottm requested a review from a team February 5, 2026 10:13
@Luthaf
Copy link
Copy Markdown
Contributor

Luthaf commented Feb 5, 2026

Could this be made to work with compute functions provided by someone else than the user running the simulation? I.e. can we write ipi.metatomic.compute_properties once, and have it usable by multiple people?

Other wishes I have would be to allow using this from the xml input directly, and allow callable classes that take arguments for initialization. (Unless this is intended to only be accessible from the scripting API!)

# in ipi/metatomic.py
class compute_properties:
    def __init__(self, template, outputs, …):
        ...
    
    def __call__(self, simulation):
        ...

and then in something like

<output prefix='script-c-p'>
    <custom_property name="custom" class="ipi.metatomic.compute_properties"> 
        template.xyz, outputs_name, … </def>
    </custom_property>
    <properties stride='2' filename='out'>[ step, custom ]</properties>
</output>

@ceriottm
Copy link
Copy Markdown
Contributor Author

ceriottm commented Feb 8, 2026

Could this be made to work with compute functions provided by someone else than the user running the simulation? I.e. can we write ipi.metatomic.compute_properties once, and have it usable by multiple people?

Other wishes I have would be to allow using this from the xml input directly, and allow callable classes that take arguments for initialization. (Unless this is intended to only be accessible from the scripting API!)

# in ipi/metatomic.py
class compute_properties:
    def __init__(self, template, outputs, …):
        ...
    
    def __call__(self, simulation):
        ...

and then in something like

<output prefix='script-c-p'>
    <custom_property name="custom" class="ipi.metatomic.compute_properties"> 
        template.xyz, outputs_name, … </def>
    </custom_property>
    <properties stride='2' filename='out'>[ step, custom ]</properties>
</output>

It already works roughly like that, look at the example in examples/features/scripting-api/run-custom-properties.py. we could have a custom class and then one could use it in their input - only they need to choose how to call it in the constructor call. But yes, this is meant to be something to be used from the scripting API, otherwise we'd have to change a lot the scope of what a PES is.

Copy link
Copy Markdown
Contributor

@GardevoirX GardevoirX left a comment

Choose a reason for hiding this comment

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

LGTM, this works well with the additional inputs recently added in metatomic. Maybe worth adding a more detailed example in atomistic cookbook after this PR in metatomic repo

@ceriottm ceriottm enabled auto-merge (squash) February 12, 2026 23:46
@ceriottm ceriottm merged commit f9175e8 into main Feb 12, 2026
7 checks passed
@ceriottm ceriottm deleted the scripting/properties branch February 13, 2026 16:27
isandom pushed a commit to isandom/i-pi that referenced this pull request Mar 18, 2026
* Add machinery to define (and output) custom properties in the scripting module
* Better names
* Added an example, including the use of a class method to compute a property
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.

3 participants