Skip to content

Add mass; add the definition of molecular orientation - #84

Open
DanqiLANG wants to merge 2 commits into
TheDisorderedOrganization:mainfrom
DanqiLANG:ExternalField
Open

Add mass; add the definition of molecular orientation#84
DanqiLANG wants to merge 2 commits into
TheDisorderedOrganization:mainfrom
DanqiLANG:ExternalField

Conversation

@DanqiLANG

Copy link
Copy Markdown

Summary

  • Store a mass for each particle in molecular systems.
  • Default to unit masses.
  • Add periodic center-of-mass calculations.
  • Add interchangeable molecular orientation definitions:
    • center of mass to a selected atom;
    • ordered normal to a triangular molecule.
  • Allow masses to be supplied through System, load_chains, and TOML input.

Notes

This PR implements molecular orientation geometry only. Coupling the
orientation to an external-field Hamiltonian will be introduced separately.

@V-Francois V-Francois 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.

Thanks for the great PR Danqi.

I have only a few minor comments, mostly about making a few things more explicit.

Also, all the checks that test that indices are in bounds, magnitudes not too low, etc. are great for now, to help make sure there is no hidden bug.
Eventually this will not be required, and just slow down things. I created issue #85 to remember to remove this in the future.

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.

That's a useful document, but I think it's better to not include this in the code base.
You can compile it on your side, then attach the PDF to the PR description, this way it's not lost, but it doesn't become part of the code

Comment thread src/orientation.jl
centre of mass to local atom `atom`.
"""
struct CenterToAtomOrientation <: OrientationDefinition
atom::Int

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 would add a comment to say that this atom index is in the "Molecular frame". i.e. if atom=1, it's the first atom of the molecule, which is not the first atom of the system (except for the first molecule).

Comment thread src/orientation.jl
reverses the orientation.
"""
struct PlaneNormalOrientation <: OrientationDefinition
atom1::Int

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.

Same comment as for the CenterToAtomOrientation class above.

Comment thread src/orientation.jl Outdated
return sum(mass * position for (mass, position) in zip(masses, unwrapped)) / total_mass
end

"""Compute an orientation from an explicit collection of molecular positions."""

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 would also add in the description that here, the positions given the function, must be the positions of the molecule only, not of the whole system, to be consistent with the definition of the atoms in the class.

This is what your code does, but it might not be obvious to a reader, because here the array positions is a slice/view of the vector of the same name of the system object.

Comment thread src/orientation.jl
return _normalise_orientation(unwrapped[definition.atom] - center)
end

function orientation(definition::PlaneNormalOrientation,

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.

same as above

Comment thread src/orientation.jl Outdated
@view(system.mass[first_atom:last_atom]),
system.box,
)
end

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.

It looks like this function is never used.
It's a relatively natural definition, so I guess you can keep it, it might be useful in the future.
I would however move it so that both definitions of molecule_center_of_mass are one after the other in the code.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 12.28070% with 50 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/orientation.jl 0.00% 49 Missing ⚠️
src/ParticlesMC.jl 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/IO/IO.jl 70.91% <100.00%> (+0.11%) ⬆️
src/molecules.jl 70.83% <100.00%> (+0.94%) ⬆️
src/ParticlesMC.jl 7.08% <0.00%> (-0.06%) ⬇️
src/orientation.jl 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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