-
Notifications
You must be signed in to change notification settings - Fork 576
[WIP] Add fix cboamd for cavity Born-Oppenheimer MD #4972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the MD framework to study vibrational strong coupling based on the cavity Born-Oppenheimer approximation by adding a new fix style fix cboamd for DeePMD-kit's LAMMPS interface.
- Adds a new LAMMPS fix implementation for cavity Born-Oppenheimer molecular dynamics
- Integrates DeepMD models for computing molecular dipoles and polarizabilities
- Implements photon coordinate evolution using velocity Verlet integration
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| source/lmp/plugin/deepmdplugin.cpp | Registers the new fix cboamd plugin with LAMMPS |
| source/lmp/fix_cboamd.h | Header file defining the FixCBOAMD class interface and member variables |
| source/lmp/fix_cboamd.cpp | Implementation of the cavity Born-Oppenheimer MD fix with DeepMD integration |
source/lmp/fix_cboamd.cpp
Outdated
| fprintf(output_file, "%d %.6f %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e", | ||
| current_step, update->dt * current_step, | ||
| dipole[0], dipole[1], dipole[2], | ||
| polarizability[0], polarizability[1], polarizability[2], | ||
| polarizability[3], polarizability[4], polarizability[5], | ||
| polarizability[6], polarizability[7], polarizability[8]); |
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output format writes 15 values but the header comment at line 160 indicates it should write Energy which is missing. The scalar energy value from compute_scalar() is not being written to the output file, creating a mismatch between the header and data columns.
| fprintf(output_file, "%d %.6f %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e", | |
| current_step, update->dt * current_step, | |
| dipole[0], dipole[1], dipole[2], | |
| polarizability[0], polarizability[1], polarizability[2], | |
| polarizability[3], polarizability[4], polarizability[5], | |
| polarizability[6], polarizability[7], polarizability[8]); | |
| double energy = compute_scalar(); | |
| fprintf(output_file, "%d %.6f %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e %.6e", | |
| current_step, update->dt * current_step, | |
| dipole[0], dipole[1], dipole[2], | |
| polarizability[0], polarizability[1], polarizability[2], | |
| polarizability[3], polarizability[4], polarizability[5], | |
| polarizability[6], polarizability[7], polarizability[8], | |
| energy); |
source/lmp/fix_cboamd.cpp
Outdated
| for (int i=0; i<nphoton; i++) { | ||
| if (n == i) return pa[i]; | ||
| if (n == nphoton+i) return qa[i]; | ||
| if (n == 2*nphoton+i) return ea[i]; | ||
| } |
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vector size is set to 3 at line 67, but compute_vector() attempts to return values for up to 3*nphoton indices. This will cause out-of-bounds access when n >= 3 and nphoton > 1, potentially leading to crashes or undefined behavior.
source/lmp/fix_cboamd.cpp
Outdated
| int idx = dp * nlocal * 3 + i * 3 + di; // index in dipole_grad_deepmd: dipole component dp, atom i, coordinate di | ||
| for (int alpha = 0; alpha < nphoton; alpha++) { | ||
| // CBOA force contribution from photon alpha | ||
| f[i][di] -= ea[alpha] * lambda_photon[alpha] * lambda_vector[alpha][di] * dipole_grad_deepmd[idx] / EV_TO_HARTREE; |
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indexing error in lambda_vector access. The code uses lambda_vector[alpha][di] but should use lambda_vector[alpha][dp] since the lambda_vector represents the coupling vector for dipole component dp, not the atomic coordinate direction di.
| f[i][di] -= ea[alpha] * lambda_photon[alpha] * lambda_vector[alpha][di] * dipole_grad_deepmd[idx] / EV_TO_HARTREE; | |
| f[i][di] -= ea[alpha] * lambda_photon[alpha] * lambda_vector[alpha][dp] * dipole_grad_deepmd[idx] / EV_TO_HARTREE; |
source/lmp/fix_cboamd.h
Outdated
| static constexpr double EV_TO_HARTREE = 0.0367493; | ||
| static constexpr double ANGSTROM_TO_BOHR = 1.88973; | ||
| static constexpr double EV_PER_ANGSTROM_TO_HARTREE_PER_BOHR = 0.0194467; | ||
| static constexpr double PS_TO_AU = 41.3413745758e3; // 1 fs = 41.3413745758 a.u. of time |
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment incorrectly states '1 fs' when the constant name indicates picoseconds (PS). The comment should read '1 ps = 41.3413745758e3 a.u. of time' to match the PS_TO_AU constant name.
| static constexpr double PS_TO_AU = 41.3413745758e3; // 1 fs = 41.3413745758 a.u. of time | |
| static constexpr double PS_TO_AU = 41.3413745758e3; // 1 ps = 41.3413745758 a.u. of time |
for more information, see https://pre-commit.ci
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| FLERR, | ||
| "fix cboamd: lambda_vector must be specified when photons enabled"); | ||
| } | ||
| // if (dt <= 0.0) error->all(FLERR,"fix cboamd: dt must be > 0"); |
Check notice
Code scanning / CodeQL
Commented-out code Note
| init_deepmd_models(); | ||
|
|
||
| // Open output file | ||
| output_file = fopen("cboamd_output.dat", "w"); |
Check failure
Code scanning / CodeQL
File created without restricting permissions High
| // // Initialize DeepMD calculations | ||
| // convert_coordinates_to_deepmd_format(); | ||
| // compute_deepmd_dipole(); | ||
| // // compute_deepmd_polarizability(); |
Check notice
Code scanning / CodeQL
Commented-out code Note
| // if (photons_enabled) { | ||
| // compute_cboa_forces(); | ||
| // } |
Check notice
Code scanning / CodeQL
Commented-out code Note
| // Update photon coordinates if enabled | ||
| // if (photons_enabled) { | ||
| // update_photon_coordinates(); | ||
| // } |
Check notice
Code scanning / CodeQL
Commented-out code Note
| // Compute DeepMD properties | ||
| convert_coordinates_to_deepmd_format(); | ||
| compute_deepmd_dipole(); | ||
| // compute_deepmd_polarizability(); |
Check notice
Code scanning / CodeQL
Commented-out code Note
| // Extract dipole components (DeepMD returns in eV/A, convert to a.u.) | ||
| // dipole[0] = dipole_deepmd[0] * ANGSTROM_TO_BOHR; | ||
| // dipole[1] = dipole_deepmd[1] * ANGSTROM_TO_BOHR; | ||
| // dipole[2] = dipole_deepmd[2] * ANGSTROM_TO_BOHR; |
Check notice
Code scanning / CodeQL
Commented-out code Note
| void FixCBOAMD::write_output() { | ||
| // Write output to file | ||
| if (comm->me == 0) { | ||
| fprintf(output_file, |
Check warning
Code scanning / CodeQL
Too few arguments to formatting function Medium
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #4972 +/- ##
==========================================
- Coverage 84.27% 83.82% -0.46%
==========================================
Files 705 706 +1
Lines 69209 69548 +339
Branches 3573 3646 +73
==========================================
- Hits 58325 58297 -28
- Misses 9743 10112 +369
+ Partials 1141 1139 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This PR is a work in progress and not ready for review right not.
This PR implements the MD framework to study vibrational strong coupling based on the cavity Born-Oppenheimer approximation. It adds a new fix style
fix cboamdfor DeePMD-kit's LAMMPS interface.