Skip to content

feat(md): add CSVR thermostat for NVT molecular dynamics#7461

Open
mintleaf84 wants to merge 6 commits into
deepmodeling:developfrom
mintleaf84:feat-csvr-thermostat
Open

feat(md): add CSVR thermostat for NVT molecular dynamics#7461
mintleaf84 wants to merge 6 commits into
deepmodeling:developfrom
mintleaf84:feat-csvr-thermostat

Conversation

@mintleaf84

Copy link
Copy Markdown

Reminder

  • Have you linked an issue with this pull request?
  • Have you added adequate unit tests and/or case tests for your pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Implements #6941

Unit Tests and/or Case Tests for my changes

  • Added CSVR test case in source/source_md/test/verlet_test.cpp
  • Test passed locally: [PASSED] 1 test

What's changed?

Implement the Canonical Sampling through Velocity Rescaling (CSVR) thermostat as described in:
G. Bussi, D. Donadio, M. Parrinello, J. Chem. Phys. 126, 014101 (2007)

Features:

  • New thermostat option: md_thermostat = csvr
  • New parameter: md_csvr_tau (characteristic time scale, default: 100.0 fs)
  • Properly samples the canonical (NVT) ensemble
  • Simple implementation with only one parameter

Usage:

md_type nvt
md_thermostat csvr
md_csvr_tau 100.0  # characteristic time scale in fs

Changed Files

File Change
source/source_io/module_parameter/md_parameter.h Add md_csvr_tau parameter
source/source_io/module_parameter/read_input_item_md.cpp Add parameter parsing for md_csvr_tau
source/source_md/verlet.h Add apply_csvr() function declaration
source/source_md/verlet.cpp Implement CSVR thermostat algorithm
source/source_md/test/verlet_test.cpp Add CSVR unit test
docs/advanced/input_files/input-main.md Add CSVR documentation

Any changes of core modules? (ignore if not applicable)

No changes to core modules. The modification is only in the MD module.

Implement the Canonical Sampling through Velocity Rescaling (CSVR)
thermostat as described in:
G. Bussi, D. Donadio, M. Parrinello, J. Chem. Phys. 126, 014101 (2007)

Features:
- New thermostat option: md_thermostat = csvr
- New parameter: md_csvr_tau (characteristic time scale)
- Properly samples the canonical (NVT) ensemble
- Simple implementation with only one parameter

Implements deepmodeling#6941
- Add csvr option to md_thermostat parameter description
- Add md_csvr_tau parameter documentation

Implements deepmodeling#6941
Add CSVR thermostat test case to verlet_test.cpp:
- Test position update correctness
- Verify temperature is in reasonable range

Implements deepmodeling#6941
@mohanchen mohanchen added Feature Discussed The features will be discussed first but will not be implemented soon Refactor Refactor ABACUS codes MD & LAM MD and Larege Atomic Models labels Jun 9, 2026
Comment thread source/source_md/verlet.cpp Outdated
}

// Get degrees of freedom
int ndeg = frozen_freedom_;

@YuLiu98 YuLiu98 Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

frozen_freedom_ is FROZEN degree instead of atom degree.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. Changed to 3 * ucell.nat - frozen_freedom_.

Comment thread source/source_md/verlet.cpp Outdated
factor = exp(-1.0 / taut);
}

// Generate Gaussian random number

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

MD_func::gaussrand() can be used to generate Gaussian random number.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. Replaced with MD_func::gaussrand().

Comment thread source/source_md/verlet.cpp Outdated
sumnoises += r * r;
}

// CSVR core formula

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This part can be more concise.

Add another factor:

double factor2 = (1-factor)*kin_target/kin_energy/ndeg;
......
double resample = factor + factor2 * (rr*rr+sumnoises ) + 2.0*rr*sqrt(factor*factor2);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. Simplified with factor2 variable.

- Fix degrees of freedom: use 3N - frozen_freedom instead of frozen_freedom
- Use MD_func::gaussrand() instead of std::random for consistency
- Simplify CSVR core formula with factor2 variable
- Remove unused #include <random>
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
@monkeycode-ai monkeycode-ai Bot force-pushed the feat-csvr-thermostat branch from a26615f to 0ce1d85 Compare June 20, 2026 15:22
@mintleaf84

Copy link
Copy Markdown
Author

Code Change Summary

All review comments have been addressed:

  1. Degrees of freedom fixed
    3 * ucell.nat - frozen_freedom_

  2. Random number generation updated
    Replaced std::random with MD_func::gaussrand()

  3. CSVR formula simplified
    Introduced factor2 variable for clarity and efficiency:

double factor2 = (1.0 - factor) * kin_target / kin_energy / ndeg;
double resample = factor + factor2 * (rr * rr + sumnoises) + 2.0 * rr * sqrt(factor * factor2);

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

Labels

Feature Discussed The features will be discussed first but will not be implemented soon MD & LAM MD and Larege Atomic Models Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants