Skip to content

Increased robustness of opconvertor.py when running on some experimental data - #456

Merged
comcon1 merged 16 commits into
NMRLipids:mainfrom
mdondrup:fix_nice_op_for_missing_std
Mar 1, 2026
Merged

Increased robustness of opconvertor.py when running on some experimental data #456
comcon1 merged 16 commits into
NMRLipids:mainfrom
mdondrup:fix_nice_op_for_missing_std

Conversation

@mdondrup

@mdondrup mdondrup commented Feb 7, 2026

Copy link
Copy Markdown
Collaborator

Made build_nice_OPdict more robust in corner cases.

  • OP data for some experiments is lacking standard deviation values, leading to an IndexError, added length check
  • added a check wether the atom is actually contained in the mapping dict to avoid a KeyError, missing atoms are skipped
  • 'nice_OPdict' contain a lot of NaN, added a function to replace those because it almost certainly will be dumped to JSON

📚 Documentation preview 📚: https://databank--456.org.readthedocs.build/

- OP data for some experiments is lacking standard deviation values
leading to an IndexError, added an additional length check
- added a check wether the atom is actually contained in the mapping dict to avoid a KeyError, missing atoms are skipped
- 'nice_OPdict' contain a lot of NaN, added a function to replace those because it almost certainly will be dumped to JSON
Comment thread tests/test_op.py Outdated
Comment on lines +96 to +97
fairmd.lipids.FMDL_DATA_PATH = "../../BilayerData"
experiments = ExperimentCollection.load_from_data("OPExperiment")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove

Comment thread tests/test_op.py Outdated
Comment on lines +80 to +81
@pytest.mark.skipif(IS_CI, reason="This test is skipped on GitHub Actions")
def test_build_nice_OPdict_with_all_experiments(self, monkeypatch, tmpdir):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add fixture loading experiments. Add 2 experiments to ToyData.

Comment thread .github/workflows/tests-min.yml Outdated
- name: run Python tests
run: |
tox -e tests-min
tox -e tests-min -r

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

revert

Comment thread .github/workflows/tests-all.yml Outdated
- name: run Python tests
run: |
tox -e tests-all
tox -e tests-all -r

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

revert

Comment on lines +66 to +68
idx = int(match[1])
row["H"] = str(idx)
if match and len(match.groups()) == 1:
idx = int(match[1])
row["H"] = str(idx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hi @comcon1 I reverted this, but it is no good. Without the safety check, 209 of the Simulation fail loading op data. I think the way it is now is the most unsafe way. We need to handle this case that there is no match more defensively. Or we need to correct all the OP data.

Comment on lines +92 to +93
if atom_c not in mdict:
continue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

raising is fine

Comment thread src/fairmd/lipids/auxiliary/opconvertor.py
Comment thread tests/test_op.py Outdated
check.is_true(has_c("g3", rdict["glycerol backbone"]))

# Check both common CI indicators
IS_CI = os.getenv("GITHUB_ACTIONS") == "true" or os.getenv("CI") == "true"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove. Using marks instead.

Comment thread tests/test_op.py Outdated
# Check both common CI indicators
IS_CI = os.getenv("GITHUB_ACTIONS") == "true" or os.getenv("CI") == "true"

@pytest.mark.skipif(IS_CI, reason="This test is skipped on GitHub Actions")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove. We use marks instead.

Comment thread tests/test_op.py Outdated
# Validate data types
assert isinstance(entry["C"], str), "C atom name is not string"
assert isinstance(entry["H"], str), "H atom name is not string"
assert isinstance(entry["OP"], (int, float)) or entry["OP"] is None, "OP is not numeric"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove "is None" from OP

mdondrup and others added 5 commits February 12, 2026 13:38
matched by the renamer.

We are now throwing a ValueException with speaking error message.
This is a more defensive approach than simply risking NoneType is not subsettable errors.

@comcon1 comcon1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will approve and merge this. Then I will work to add functionality in a separate PR.

@comcon1
comcon1 merged commit 32cafe5 into NMRLipids:main Mar 1, 2026
10 of 11 checks passed
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