Skip to content

WIP: Added instance method to generate MolBar from Structure#236

Open
crjacinto wants to merge 8 commits into
faccts:mainfrom
crjacinto:molbar
Open

WIP: Added instance method to generate MolBar from Structure#236
crjacinto wants to merge 8 commits into
faccts:mainfrom
crjacinto:molbar

Conversation

@crjacinto

@crjacinto crjacinto commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Closes Issues

Closes #227

Description

  • Added an instance method that generates the Molecular Barcode from Structure.

Release Notes

(Project adheres to Keep a Changelog; Every entry should start in upper-case and end with (#<pr-id>); Remove sections that don't apply)

Changed

  • Modified structure.py.

@crjacinto crjacinto requested a review from a team as a code owner April 29, 2026 13:04
@haneug haneug added enhancement New feature or request side input Concerning writing ORCA input labels Apr 30, 2026
@haneug

haneug commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

@crjacinto please repair the title and the description of the PR

@crjacinto crjacinto changed the title Added class method to generate the Molecular Barcode (Molbar) from St… Added instance method to generate MolBar from Structure Class Apr 30, 2026
@crjacinto crjacinto changed the title Added instance method to generate MolBar from Structure Class Added instance method to generate MolBar from Structure Apr 30, 2026
@crjacinto

Copy link
Copy Markdown
Contributor Author

@crjacinto please repair the title and the description of the PR

Done

@haneug haneug left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice PR! Please split the function according to the return types and change the docstring to numpy style. Also an enum for the mode would be a good thing for verification I think.

Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
@crjacinto crjacinto changed the title Added instance method to generate MolBar from Structure WIP: Added instance method to generate MolBar from Structure Jun 10, 2026
@crjacinto

crjacinto commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

At this point, the latest commit of this code is compatible with the features developed for the RMSD-RotConst implementation (#230). The unit tests are failing since some of the features that are being used now come from the RMSD-RotConst code which has not yet been merged here. Once the other code is merged, I'm going to rebase this commit and it would be ready for review

@crjacinto crjacinto requested a review from haneug July 16, 2026 08:47

@haneug haneug left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work, I would suggest to move the molbar import from the module level to the function level. Also, please add an entry to CHANGELOG.md and I think there was one comment about to_molbar which is not anymore.


The total charge is taken from `charge`.

MolBar is **not** a dependency of OPI and must be installed separately::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here you write molbar is not a dependency and below you write it is optional. We should clearly decide for one thing and go with it. Please make it an optional dependency and pin a version number we want to use.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I added it as an optional dependency please document it accordingly.

mode: "MolBarMode | str" = MolBarMode.MB,
) -> str:
"""
Compute the MolBar barcode string for this `Structure`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add the link to the paper here? With the doi?

Comment thread src/opi/utils/molbar.py
# MolBar is an optional dependency. The decorator below guards every method
# that calls it and raises a clear ImportError if it is not installed.
try:
from molbar.barcode import get_molbar_from_coordinates # type: ignore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes molbar get imported whenever opi.utils.molbar is imported and since structure.py imports it, that means on any from opi.core import Calculator etc. it will be imported. Molbar is a large package with heavy dependencies, so for users who have it installed this slows down every OPI import even if they never compute a barcode. Suggestion: move the import into call_molbar() so it only happens on first use. Note that requires_molbar currently relies on this module-level import (it checks get_molbar_from_coordinates() is None), so it would need to switch to something like importlib.util.find_spec("molbar").

def test_topo_mode(self, water):
"""`calculate_molbar_data()` with `mode="topo"` should return the topology barcode."""
barcode, _ = water.calculate_molbar_data(mode="topo")
assert barcode == "TopoBar | 1.1.3 | OH2 | -84 20 344 | 80"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we replace 1.1.3 by molbar.__version__? Is that possible?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When I looked at molbar.__version__) it raised an AttributeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request side input Concerning writing ORCA input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simple integration of MolBar into OPI´s Structure Object

3 participants