From 9a796edf456db6b32caed2a4b0f702d2ad0bb1f0 Mon Sep 17 00:00:00 2001 From: skfegan Date: Tue, 4 Nov 2025 15:34:35 +0000 Subject: [PATCH 01/12] Merging forces from separate trajectory file --- CodeEntropy/config/arg_config_manager.py | 8 ++++++- CodeEntropy/run.py | 28 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CodeEntropy/config/arg_config_manager.py b/CodeEntropy/config/arg_config_manager.py index dab98dc..0e49ea4 100644 --- a/CodeEntropy/config/arg_config_manager.py +++ b/CodeEntropy/config/arg_config_manager.py @@ -12,7 +12,13 @@ "top_traj_file": { "type": str, "nargs": "+", - "help": "Path to Structure/topology file followed by Trajectory file(s)", + "help": "Path to structure/topology file followed by trajectory file", + }, + "force_file": { + "type": str, + "nargs": "+", + "default": None, + "help": "Optional path to force file if forces are not in trajectory file", }, "selection_string": { "type": str, diff --git a/CodeEntropy/run.py b/CodeEntropy/run.py index 38f3039..0eb1307 100644 --- a/CodeEntropy/run.py +++ b/CodeEntropy/run.py @@ -250,6 +250,34 @@ def run_entropy_workflow(self): logger.debug(f"Loading Universe with {tprfile} and {trrfile}") u = mda.Universe(tprfile, trrfile) + # If forces are in separate file merge them with the + # coordinates from the trajectory file + forcefile = args.force_file[0] + if forcefile is not None: + u_force = mda.Universe(tprfile, forcefile) + select_atom = u.select_atoms("all") + select_atom_force = u_force.select_atoms("all") + + coordinates = ( + AnalysisFromFunction( + lambda ag: ag.positions.copy(), select_atom + ) + .run() + .results["timeseries"] + ) + forces = ( + AnalysisFromFunction( + lambda ag: ag.positions.copy(), select_atom_force + ) + .run() + .results["timeseries"] + ) + + new_universe = mda.Merge(select_atom) + new_universe.load_new(coordinates, forces=forces) + + u = new_universe + self._config_manager.input_parameters_validation(u, args) # Create LevelManager instance From 8209f8717eb1c0d191d3975961521258bfee57e2 Mon Sep 17 00:00:00 2001 From: skfegan Date: Wed, 5 Nov 2025 11:40:12 +0000 Subject: [PATCH 02/12] correcting merge universe and adding to the docs --- CodeEntropy/config/arg_config_manager.py | 6 +++++- CodeEntropy/entropy.py | 2 +- CodeEntropy/run.py | 27 +++++++----------------- docs/config.yaml | 2 ++ docs/faq.rst | 10 ++++++++- docs/getting_started.rst | 12 +++++++++-- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/CodeEntropy/config/arg_config_manager.py b/CodeEntropy/config/arg_config_manager.py index 0e49ea4..634fea2 100644 --- a/CodeEntropy/config/arg_config_manager.py +++ b/CodeEntropy/config/arg_config_manager.py @@ -16,10 +16,14 @@ }, "force_file": { "type": str, - "nargs": "+", "default": None, "help": "Optional path to force file if forces are not in trajectory file", }, + "file_format": { + "type": str, + "default": None, + "help": "String for file format as recognised by MDAnalysis", + }, "selection_string": { "type": str, "help": "Selection string for CodeEntropy", diff --git a/CodeEntropy/entropy.py b/CodeEntropy/entropy.py index fa75111..75acfe5 100644 --- a/CodeEntropy/entropy.py +++ b/CodeEntropy/entropy.py @@ -86,7 +86,7 @@ def execute(self): ) reduced_atom, number_molecules, levels, groups = self._initialize_molecules() - + logger.debug(f"Universe 3: {reduced_atom}") water_atoms = self._universe.select_atoms("water") water_resids = set(res.resid for res in water_atoms.residues) diff --git a/CodeEntropy/run.py b/CodeEntropy/run.py index 0eb1307..68e765a 100644 --- a/CodeEntropy/run.py +++ b/CodeEntropy/run.py @@ -247,14 +247,16 @@ def run_entropy_workflow(self): # Load MDAnalysis Universe tprfile = args.top_traj_file[0] trrfile = args.top_traj_file[1:] + fileformat = args.file_format logger.debug(f"Loading Universe with {tprfile} and {trrfile}") - u = mda.Universe(tprfile, trrfile) + u = mda.Universe(tprfile, trrfile, format=fileformat) # If forces are in separate file merge them with the # coordinates from the trajectory file - forcefile = args.force_file[0] + forcefile = args.force_file if forcefile is not None: - u_force = mda.Universe(tprfile, forcefile) + logger.debug(f"Loading Universe with {forcefile}") + u_force = mda.Universe(tprfile, forcefile, format=fileformat) select_atom = u.select_atoms("all") select_atom_force = u_force.select_atoms("all") @@ -273,6 +275,7 @@ def run_entropy_workflow(self): .results["timeseries"] ) + logger.debug("Merging forces with coordinates universe.") new_universe = mda.Merge(select_atom) new_universe.load_new(coordinates, forces=forces) @@ -339,15 +342,8 @@ def new_U_select_frame(self, u, start=None, end=None, step=1): .run() .results["timeseries"][start:end:step] ) - dimensions = ( - AnalysisFromFunction(lambda ag: ag.dimensions.copy(), select_atom) - .run() - .results["timeseries"][start:end:step] - ) u2 = mda.Merge(select_atom) - u2.load_new( - coordinates, format=MemoryReader, forces=forces, dimensions=dimensions - ) + u2.load_new(coordinates, format=MemoryReader, forces=forces) logger.debug(f"MDAnalysis.Universe - reduced universe: {u2}") return u2 @@ -379,15 +375,8 @@ def new_U_select_atom(self, u, select_string="all"): .run() .results["timeseries"] ) - dimensions = ( - AnalysisFromFunction(lambda ag: ag.dimensions.copy(), select_atom) - .run() - .results["timeseries"] - ) u2 = mda.Merge(select_atom) - u2.load_new( - coordinates, format=MemoryReader, forces=forces, dimensions=dimensions - ) + u2.load_new(coordinates, format=MemoryReader, forces=forces) logger.debug(f"MDAnalysis.Universe - reduced universe: {u2}") return u2 diff --git a/docs/config.yaml b/docs/config.yaml index 44fbb3e..3f6fd8f 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -2,6 +2,8 @@ run1: top_traj_file: ["1AKI_prod.tpr", "1AKI_prod.trr"] + force_file: + file_formate: selection_string: 'all' start: 0 end: 500 diff --git a/docs/faq.rst b/docs/faq.rst index aec29b1..a119a27 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -4,7 +4,15 @@ Frequently asked questions Why do I get a ``WARNING`` about invalid eigenvalues? ----------------------------------------------------- -Insufficient sampling might introduce noise and cause matrix elements to deviate to values that would not reflect the uncorrelated nature of force-force covariance of distantly positioned residues.Try increasing the sampling time. This is especially true at the residue level. +Insufficient sampling might introduce noise and cause matrix elements to deviate to values that would not reflect the uncorrelated nature of force-force covariance of distantly positioned residues. +Try increasing the sampling time. +This is especially true at the residue level. For example in a lysozyme system, the residue level contains the largest force and torque covariance matrices because at this level we have the largest number of beads (which is equal to the number of residues in a protein) compared to the molecule level (3 beads) and united-atom level (~10 beads per amino acid). +What do I do if there is an error from MDAnalysis not recognising the file type? +------------------------------------------------------------------------------- + +Use the file_format option. +The MDAnalysis documentation has a list of acceptable formats: https://userguide.mdanalysis.org/1.1.1/formats/index.html#id1. +The first column of their table gives you the string you need (case sensitive). diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 6218cff..7fe9071 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -81,10 +81,18 @@ The top_traj_file argument is necessary to identify your simulation data, the ot - Description - Default - Type - * - ``--top_traj_file`` - - Path to Structure/topology file followed by Trajectory file(s). Any MDAnalysis readable files should work (for example ``GROMACS TPR and TRR`` or ``AMBER PRMTOP and NETCDF``). You will need to output the **coordinates** and **forces** to the **same file** . + * - ``--top_traj_file`` + - Path to Structure/topology file followed by Trajectory file. Any MDAnalysis readable files should work (for example ``GROMACS TPR and TRR`` or ``AMBER PRMTOP and NETCDF``). - Required, no default value - list of ``str`` + * - ``--force_file`` + - Path to a file with forces. This option should be used if the forces are not in the same file as the coordinates. It is expected that the force file has the same number of atoms and frames as the trajectory file. Any MDAnalysis readable files should work (for example ``AMBER NETCDF`` or ``LAMMPS DCD``). + - None + - ``str`` + * - ``--file_format`` + - Use to tell MDAnalysis the format if the trajectory or force file does not have the standard extension recognised by MDAnalysis. + - None + - ``str`` * - ``--selection_string`` - Selection string for CodeEntropy such as protein or resid, refer to ``MDAnalysis.select_atoms`` for more information. - ``"all"``: select all atom in trajectory From 1ffc3c313c2fed6d31e0f430053ed1608ea437ba Mon Sep 17 00:00:00 2001 From: skfegan Date: Fri, 7 Nov 2025 10:47:01 +0000 Subject: [PATCH 03/12] adding kcal_force_unit input parameter to get forces correct --- CodeEntropy/config/arg_config_manager.py | 5 +++++ CodeEntropy/run.py | 4 ++++ tests/test_CodeEntropy/test_run.py | 20 +++++++------------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CodeEntropy/config/arg_config_manager.py b/CodeEntropy/config/arg_config_manager.py index 634fea2..799b950 100644 --- a/CodeEntropy/config/arg_config_manager.py +++ b/CodeEntropy/config/arg_config_manager.py @@ -24,6 +24,11 @@ "default": None, "help": "String for file format as recognised by MDAnalysis", }, + "kcal_force_units": { + "type": bool, + "default": False, + "help": "Set this to True if you have a separate force file with nonSI units.", + }, "selection_string": { "type": str, "help": "Selection string for CodeEntropy", diff --git a/CodeEntropy/run.py b/CodeEntropy/run.py index 68e765a..71b55ad 100644 --- a/CodeEntropy/run.py +++ b/CodeEntropy/run.py @@ -275,6 +275,10 @@ def run_entropy_workflow(self): .results["timeseries"] ) + if args.kcal_force_units: + # Convert from kcal to kJ + forces *= 4.184 + logger.debug("Merging forces with coordinates universe.") new_universe = mda.Merge(select_atom) new_universe.load_new(coordinates, forces=forces) diff --git a/tests/test_CodeEntropy/test_run.py b/tests/test_CodeEntropy/test_run.py index 54def3e..abd8c27 100644 --- a/tests/test_CodeEntropy/test_run.py +++ b/tests/test_CodeEntropy/test_run.py @@ -308,6 +308,8 @@ def test_run_entropy_workflow(self): run_manager._config_manager.load_config.return_value = { "test_run": { "top_traj_file": ["/path/to/tpr", "/path/to/trr"], + "force_file": None, + "file_format": None, "selection_string": "all", "output_file": "output.json", "verbose": True, @@ -335,6 +337,8 @@ def test_run_entropy_workflow(self): mock_args.output_file = "output.json" mock_args.verbose = True mock_args.top_traj_file = ["/path/to/tpr", "/path/to/trr"] + mock_args.force_file = None + mock_args.file_format = None mock_args.selection_string = "all" parser = run_manager._config_manager.setup_argparse.return_value parser.parse_known_args.return_value = (mock_args, []) @@ -351,7 +355,9 @@ def test_run_entropy_workflow(self): run_manager.run_entropy_workflow() - mock_universe.assert_called_once_with("/path/to/tpr", ["/path/to/trr"]) + mock_universe.assert_called_once_with( + "/path/to/tpr", ["/path/to/trr"], format=None + ) mock_entropy_manager.execute.assert_called_once() def test_run_configuration_warning(self): @@ -522,7 +528,6 @@ def test_new_U_select_frame(self, MockMerge, MockAnalysisFromFunction): # Mock AnalysisFromFunction results for coordinates, forces, and dimensions coords = np.random.rand(10, 100, 3) forces = np.random.rand(10, 100, 3) - dims = np.random.rand(10, 3) mock_coords_analysis = MagicMock() mock_coords_analysis.run.return_value.results = {"timeseries": coords} @@ -530,14 +535,10 @@ def test_new_U_select_frame(self, MockMerge, MockAnalysisFromFunction): mock_forces_analysis = MagicMock() mock_forces_analysis.run.return_value.results = {"timeseries": forces} - mock_dims_analysis = MagicMock() - mock_dims_analysis.run.return_value.results = {"timeseries": dims} - # Set the side effects for the three AnalysisFromFunction calls MockAnalysisFromFunction.side_effect = [ mock_coords_analysis, mock_forces_analysis, - mock_dims_analysis, ] # Mock the merge operation @@ -557,7 +558,6 @@ def test_new_U_select_frame(self, MockMerge, MockAnalysisFromFunction): # Assert that the arrays are passed correctly np.testing.assert_array_equal(args[0], coords) np.testing.assert_array_equal(kwargs["forces"], forces) - np.testing.assert_array_equal(kwargs["dimensions"], dims) # Check if format was included in the kwargs self.assertIn("format", kwargs) @@ -576,7 +576,6 @@ def test_new_U_select_atom(self, MockMerge, MockAnalysisFromFunction): # Mock AnalysisFromFunction results for coordinates, forces, and dimensions coords = np.random.rand(10, 100, 3) forces = np.random.rand(10, 100, 3) - dims = np.random.rand(10, 3) mock_coords_analysis = MagicMock() mock_coords_analysis.run.return_value.results = {"timeseries": coords} @@ -584,14 +583,10 @@ def test_new_U_select_atom(self, MockMerge, MockAnalysisFromFunction): mock_forces_analysis = MagicMock() mock_forces_analysis.run.return_value.results = {"timeseries": forces} - mock_dims_analysis = MagicMock() - mock_dims_analysis.run.return_value.results = {"timeseries": dims} - # Set the side effects for the three AnalysisFromFunction calls MockAnalysisFromFunction.side_effect = [ mock_coords_analysis, mock_forces_analysis, - mock_dims_analysis, ] # Mock the merge operation @@ -613,7 +608,6 @@ def test_new_U_select_atom(self, MockMerge, MockAnalysisFromFunction): # Assert that the arrays are passed correctly np.testing.assert_array_equal(args[0], coords) np.testing.assert_array_equal(kwargs["forces"], forces) - np.testing.assert_array_equal(kwargs["dimensions"], dims) # Check if format was included in the kwargs self.assertIn("format", kwargs) From 12cde8f8fc643aea646e8d23bdbeaa0aa9de0073 Mon Sep 17 00:00:00 2001 From: harryswift01 Date: Thu, 16 Oct 2025 14:18:10 +0100 Subject: [PATCH 04/12] include orcid information for `Harry Swift` within `CITATION.cff` file --- CITATION.cff | 1 + 1 file changed, 1 insertion(+) diff --git a/CITATION.cff b/CITATION.cff index cd54050..8dd0a2e 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -56,6 +56,7 @@ authors: family-names: Swift email: harry.swift@stfc.ac.uk affiliation: 'STFC, Scientific Computing' + orcid: 'https://orcid.org/0009-0007-3323-753X' repository-code: 'https://github.com/CCPBioSim/CodeEntropy' url: 'https://ccpbiosim.github.io/CodeEntropy/' abstract: >- From 1a5fec0e9502e542cc426ce396f3fe2da0a06292 Mon Sep 17 00:00:00 2001 From: harryswift01 Date: Thu, 16 Oct 2025 14:22:14 +0100 Subject: [PATCH 05/12] update `version` and `date-released` within `CITATION.cff` file --- CITATION.cff | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 8dd0a2e..1f50a2c 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -76,5 +76,5 @@ keywords: - biomolecular simulations - protein flexibility license: MIT -version: 0.3.6 -date-released: '2022-07-06' +version: 1.0.3 +date-released: '2025-09-29' From c51c801089eed805532378466cfe57e36614ebc3 Mon Sep 17 00:00:00 2001 From: harryswift01 Date: Thu, 16 Oct 2025 14:48:41 +0100 Subject: [PATCH 06/12] updated description within `__init__.py` file --- CodeEntropy/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CodeEntropy/__init__.py b/CodeEntropy/__init__.py index 34402c3..06e3df1 100644 --- a/CodeEntropy/__init__.py +++ b/CodeEntropy/__init__.py @@ -1,9 +1,11 @@ """ CodeEntropy -CodeEntropy tool with POSEIDON code integrated to form a complete and generally -applicable set of tools for computing entropy of macromolecular systems from the -forces sampled in a MD simulation. +CodeEntropy is a Python package for computing the configurational entropy of +macromolecular systems using forces sampled from molecular dynamics (MD) simulations. +It implements the multiscale cell correlation method to provide accurate and efficient +entropy estimates, supporting a wide range of applications in molecular simulation +and statistical mechanics. """ __version__ = "1.0.3" From 9f6dc733a02b0134a6cb430bef436abaf8018426 Mon Sep 17 00:00:00 2001 From: harryswift01 Date: Thu, 16 Oct 2025 15:18:31 +0100 Subject: [PATCH 07/12] add `CITATION.cff` version update to release workflow: - Update `.github/workflows/release.yaml` to bump `CITATION.cff` version and date-released automatically - Keep version in `__init__.py` and `CITATION.cff` in sync during releases - Fully automated in CI, no manaul edits needed --- .github/workflows/release.yaml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d18357f..e23d8ba 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -48,8 +48,16 @@ jobs: - name: checkout uses: actions/checkout@v5.0.0 - - name: Change version in repo - run: sed -i "s/__version__ =.*/__version__ = \"${{ github.event.inputs.version }}\"/g" CodeEntropy/__init__.py + - name: Change version in repo and CITATION.cff + run: | + # Update Python package version + sed -i "s/__version__ =.*/__version__ = \"${{ github.event.inputs.version }}\"/g" CodeEntropy/__init__.py + + # Update CITATION.cff version and date-released + if [ -f CITATION.cff ]; then + sed -i -E "s/^(version:\s*).*/\1${{ github.event.inputs.version }}/" CITATION.cff + sed -i -E "s/^(date-released:\s*).*/\1'$(date -u +%F)'/" CITATION.cff + fi - name: send PR id: pr_id @@ -61,6 +69,7 @@ jobs: body: | Update version - Update the __init__.py with new release + - Update CITATION.cff version & date-released - Auto-generated by [CI] committer: version-updater author: version-updater From 94dfbbb3cb3d98019bd9040fac3052693b36be6c Mon Sep 17 00:00:00 2001 From: harryswift01 Date: Wed, 5 Nov 2025 09:31:17 +0000 Subject: [PATCH 08/12] Update `CODE_OF_CONDUCT.md` --- CODE_OF_CONDUCT.md | 151 ++++++++++++++++++++++++++++++--------------- 1 file changed, 101 insertions(+), 50 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 79c3538..729da91 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -2,76 +2,127 @@ ## Our Pledge -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, -body size, disability, ethnicity, gender identity and expression, level of -experience, nationality, personal appearance, race, religion, or sexual -identity and orientation. +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. ## Our Standards -Examples of behavior that contributes to creating a positive environment include: +Examples of behavior that contributes to a positive environment for our +community include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community -Examples of unacceptable behavior by participants include: +Examples of unacceptable behavior include: -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting - -## Our Responsibilities +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. +## Enforcement Responsibilities -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. -Moreover, project maintainers will strive to offer feedback and advice to -ensure quality and consistency of contributions to the code. Contributions -from outside the group of project maintainers are strongly welcomed but the -final decision as to whether commits are merged into the codebase rests with -the team of project maintainers. +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. ## Scope -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an -appointed representative at an online or offline event. Representation of a -project may be further defined and clarified by project maintainers. +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at 'lpchungaa@gmail.com'. The project team will -review and investigate all complaints, and will respond in a way that it deems -appropriate to the circumstances. The project team is obligated to maintain -confidentiality with regard to the reporter of an incident. Further details of -specific enforcement policies may be posted separately. +reported to the community leaders responsible for enforcement at +ccpbiosim@stfc.ac.uk. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 1.4, available at -[http://contributor-covenant.org/version/1/4][version] +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. \ No newline at end of file From 949d9e2ecd4afa45e274b09f7b7e871841ab1f77 Mon Sep 17 00:00:00 2001 From: harryswift01 Date: Wed, 5 Nov 2025 10:01:04 +0000 Subject: [PATCH 09/12] update `CONTRIBUTING.md` --- .github/CONTRIBUTING.md | 185 ++++++++++++++++++++++++++++++++-------- 1 file changed, 150 insertions(+), 35 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 0b59544..ba588b0 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,42 +1,157 @@ -# How to contribute -We welcome contributions from external contributors, and this document -describes how to merge code changes into this CodeEntropy. +# Contributing to CodeEntropy + +We welcome contributions from the community to improve and extend CodeEntropy. This guide outlines how to get started, make changes, and submit them for review. + +--- ## Getting Started -* Make sure you have a [GitHub account](https://github.com/signup/free). -* [Fork](https://help.github.com/articles/fork-a-repo/) this repository on GitHub. -* On your local machine, - [clone](https://help.github.com/articles/cloning-a-repository/) your fork of - the repository. +1. **Create a GitHub account**: [Sign up here](https://github.com/signup/free). +2. **Fork the repository**: [How to fork](https://help.github.com/articles/fork-a-repo/). +3. **Clone your fork locally**: + ```bash + git clone https://github.com/YOUR_USERNAME/CodeEntropy.git + cd CodeEntropy + ``` + +4. **Create a virtual environment**: + ```bash + python -m venv codeentropy-dev + source codeentropy-dev/bin/activate # Linux/macOS + codeentropy-dev\Scripts\activate # Windows + ``` + +5. **Install development dependencies**: + ```bash + pip install -e ".[testing,docs,pre-commit]" + pre-commit install + ``` + +--- ## Making Changes -* Add some really awesome code to your local fork. It's usually a [good - idea](http://blog.jasonmeridth.com/posts/do-not-issue-pull-requests-from-your-master-branch/) - to make changes on a - [branch](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/) - with the branch name relating to the feature you are going to add. -* When you are ready for others to examine and comment on your new feature, - navigate to your fork of CodeEntropy on GitHub and open a [pull - request](https://help.github.com/articles/using-pull-requests/) (PR). Note that - after you launch a PR from one of your fork's branches, all - subsequent commits to that branch will be added to the open pull request - automatically. Each commit added to the PR will be validated for - mergability, compilation and test suite compliance; the results of these tests - will be visible on the PR page. -* If you're providing a new feature, you must add test cases and documentation. -* When the code is ready to go, make sure you run the test suite using pytest. -* When you're ready to be considered for merging, check the "Ready to go" - box on the PR page to let the CodeEntropy devs know that the changes are complete. - The code will not be merged until this box is checked, the continuous - integration returns checkmarks, - and multiple core developers give "Approved" reviews. - -# Additional Resources - -* [General GitHub documentation](https://help.github.com/) -* [PR best practices](http://codeinthehole.com/writing/pull-requests-and-other-good-practices-for-teams-using-github/) -* [A guide to contributing to software packages](http://www.contribution-guide.org) -* [Thinkful PR example](http://www.thinkful.com/learn/github-pull-request-tutorial/#Time-to-Submit-Your-First-PR) +- **Use a feature branch**: + ```bash + git checkout -b 123-fix-levels + ``` + You cannot commit directly to `main` as this is a protected branch. + +- **Add your code**, documentation, and tests. All new features must include: + - Unit tests + - Documentation updates + - Compliance with coding standards + +- **Run tests**: + ```bash + pytest -v + pytest --cov CodeEntropy --cov-report=term-missing + ``` + +- **Run pre-commit checks**: + These ensure formatting, linting, and basic validations. + ```bash + pre-commit run --all-files + ``` + +--- + +## Submitting a Pull Request (PR) + +1. Push your branch to GitHub. +2. Open a [pull request](https://help.github.com/articles/using-pull-requests/). +3. Use the templated Pull Request template to fill out: + - A summary of what the PR is doing + - List all the changes that the PR is proposing + - Add how these changes will impact the repository +4. Ensure: + - All tests pass + - Pre-commit checks pass + - Documentation is updated + +5. Your PR will be reviewed by core developers. At least one approval is required before merging. + +--- + +## Running Tests + +- Full suite: + ```bash + pytest -v + ``` +- With coverage: + ```bash + pytest --cov CodeEntropy --cov-report=term-missing + ``` +- Specific module: + ```bash + pytest CodeEntropy/tests/test_CodeEntropy/test_levels.py + ``` +- Specific test: + ```bash + pytest CodeEntropy/tests/test_CodeEntropy/test_levels.py::test_select_levels + ``` + +--- + +## Coding Standards + +We use **pre-commit hooks** to enforce style and quality: + +- **Black** for formatting +- **Isort** for import sorting +- **Flake8** for linting +- **Pre-commit-hooks** for: + - Large file detection + - AST validity + - Merge conflict detection + - YAML/TOML syntax checks + +--- + +## Continuous Integration (CI) + +All PRs trigger GitHub Actions to: + +- Run tests +- Check style +- Build documentation +- Validate versioning + +--- + +## Building Documentation + +Build locally: +```bash +cd docs +make html +``` + +View in browser: +``` +docs/build/html/index.html +``` + +Edit docs in: +- `docs/science.rst` +- `docs/developer_guide.rst` + +--- + +## Reporting Issues + +Found a bug or want a feature? + +1. Open an issue on GitHub. +2. Include a clear description and input files if relevant. + +--- + +## Additional Resources + +- [GitHub Docs](https://help.github.com/) +- [PR Best Practices](http://codeinthehole.com/writing/pull-requests-and-other-good-practices-for-teams-using-github/) +- [Contribution Guide](http://www.contribution-guide.org) +- [Thinkful PR Tutorial](http://www.thinkful.com/learn/github-pull-request-tutorial/#Time-to-Submit-Your-First-PR) From 993535ac8b45a49aa1fc5262f74ba38e2c925f1e Mon Sep 17 00:00:00 2001 From: Swift Date: Wed, 5 Nov 2025 12:53:26 +0000 Subject: [PATCH 10/12] refined `CONTRIBUTING.md` avoiding duplication with the docs --- .github/CONTRIBUTING.md | 164 +++++++++------------------------------- 1 file changed, 36 insertions(+), 128 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index ba588b0..5b23339 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,157 +1,65 @@ - # Contributing to CodeEntropy -We welcome contributions from the community to improve and extend CodeEntropy. This guide outlines how to get started, make changes, and submit them for review. - ---- +Thank you for your interest in contributing to **CodeEntropy**! -## Getting Started +We’re excited to collaborate with developers, researchers, and community members to make CodeEntropy better for everyone. -1. **Create a GitHub account**: [Sign up here](https://github.com/signup/free). -2. **Fork the repository**: [How to fork](https://help.github.com/articles/fork-a-repo/). -3. **Clone your fork locally**: - ```bash - git clone https://github.com/YOUR_USERNAME/CodeEntropy.git - cd CodeEntropy - ``` - -4. **Create a virtual environment**: - ```bash - python -m venv codeentropy-dev - source codeentropy-dev/bin/activate # Linux/macOS - codeentropy-dev\Scripts\activate # Windows - ``` - -5. **Install development dependencies**: - ```bash - pip install -e ".[testing,docs,pre-commit]" - pre-commit install - ``` +This guide explains how to set up your environment, make changes, and submit them for review. Whether you’re fixing a bug, improving documentation, or adding new features, every contribution makes a difference. --- -## Making Changes - -- **Use a feature branch**: - ```bash - git checkout -b 123-fix-levels - ``` - You cannot commit directly to `main` as this is a protected branch. - -- **Add your code**, documentation, and tests. All new features must include: - - Unit tests - - Documentation updates - - Compliance with coding standards +## Getting Started -- **Run tests**: - ```bash - pytest -v - pytest --cov CodeEntropy --cov-report=term-missing - ``` +Before contributing, please review the [Developer Guide](https://codeentropy.readthedocs.io/en/latest/developer_guide.html). +It covers CodeEntropy’s architecture, setup instructions, and contribution workflow. -- **Run pre-commit checks**: - These ensure formatting, linting, and basic validations. - ```bash - pre-commit run --all-files - ``` +If you’re new to the project, we also recommend: +- Reading the [README](../README.md) for an overview and installation details. +- Checking open [issues](https://github.com/CCPBioSim/CodeEntropy/issues) labeled **good first issue** to find beginner-friendly tasks. --- ## Submitting a Pull Request (PR) -1. Push your branch to GitHub. -2. Open a [pull request](https://help.github.com/articles/using-pull-requests/). -3. Use the templated Pull Request template to fill out: - - A summary of what the PR is doing - - List all the changes that the PR is proposing - - Add how these changes will impact the repository -4. Ensure: - - All tests pass - - Pre-commit checks pass - - Documentation is updated - -5. Your PR will be reviewed by core developers. At least one approval is required before merging. - ---- - -## Running Tests - -- Full suite: - ```bash - pytest -v - ``` -- With coverage: - ```bash - pytest --cov CodeEntropy --cov-report=term-missing - ``` -- Specific module: - ```bash - pytest CodeEntropy/tests/test_CodeEntropy/test_levels.py - ``` -- Specific test: - ```bash - pytest CodeEntropy/tests/test_CodeEntropy/test_levels.py::test_select_levels - ``` - ---- - -## Coding Standards +When you’re ready to submit your work: -We use **pre-commit hooks** to enforce style and quality: +1. **Push your branch** to GitHub. +2. **Open a [pull request](https://help.github.com/articles/using-pull-requests/)** against the `main` branch. +3. **Fill out the PR template**, including: + - A concise summary of what your PR does + - A list of all changes introduced + - Details on how these changes affect the repository (features, tests, documentation, etc.) +4. **Verify before submission**: + - All tests pass + - Pre-commit checks succeed + - Documentation is updated where applicable +5. **Review process**: + - Your PR will be reviewed by the core development team. + - At least **one approval** is required before merging. -- **Black** for formatting -- **Isort** for import sorting -- **Flake8** for linting -- **Pre-commit-hooks** for: - - Large file detection - - AST validity - - Merge conflict detection - - YAML/TOML syntax checks +We aim to provide constructive feedback quickly and appreciate your patience during the review process. --- -## Continuous Integration (CI) - -All PRs trigger GitHub Actions to: - -- Run tests -- Check style -- Build documentation -- Validate versioning - ---- - -## Building Documentation +## Reporting Issues -Build locally: -```bash -cd docs -make html -``` +Found a bug or have a feature request? -View in browser: -``` -docs/build/html/index.html -``` +1. **Open a new issue** on GitHub. +2. Provide a **clear and descriptive title**. +3. Include: + - Steps to reproduce the issue (if applicable) + - Expected vs. actual behavior + - Relevant logs, screenshots, or input files -Edit docs in: -- `docs/science.rst` -- `docs/developer_guide.rst` +Well-documented issues help us address problems faster and keep CodeEntropy stable and robust. --- -## Reporting Issues - -Found a bug or want a feature? +## Additional Resources -1. Open an issue on GitHub. -2. Include a clear description and input files if relevant. +- [GitHub Docs](https://help.github.com/) --- -## Additional Resources - -- [GitHub Docs](https://help.github.com/) -- [PR Best Practices](http://codeinthehole.com/writing/pull-requests-and-other-good-practices-for-teams-using-github/) -- [Contribution Guide](http://www.contribution-guide.org) -- [Thinkful PR Tutorial](http://www.thinkful.com/learn/github-pull-request-tutorial/#Time-to-Submit-Your-First-PR) +Thank you for helping improve **CodeEntropy**, your contributions make open source stronger! From 5c03f804e68fef1fcca79f19478b579a079ca9dc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:45:49 +0000 Subject: [PATCH 11/12] Bump softprops/action-gh-release from 2.4.1 to 2.4.2 Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 2.4.1 to 2.4.2. - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/v2.4.1...v2.4.2) --- updated-dependencies: - dependency-name: softprops/action-gh-release dependency-version: 2.4.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e23d8ba..ef622a5 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -113,7 +113,7 @@ jobs: steps: - name: create release - uses: softprops/action-gh-release@v2.4.1 + uses: softprops/action-gh-release@v2.4.2 with: name: v${{ github.event.inputs.version }} generate_release_notes: true From c247cbba2820ec2c69d65763197724f17fe520b9 Mon Sep 17 00:00:00 2001 From: harryswift01 Date: Mon, 10 Nov 2025 09:55:33 +0000 Subject: [PATCH 12/12] add atomic unit tests for force merge logic in `run_entropy_workflow`: - `test_merges_forcefile_correctly`: verifies that coordinate and force universes are merged and loaded correctly - `test_converts_kcal_to_kj`: checks that forces are scaled by 4.184 when `kcal_force_units=True` - `test_logs_debug_messages`: ensures expected debug logs are emitted during force merge --- tests/test_CodeEntropy/test_run.py | 177 +++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) diff --git a/tests/test_CodeEntropy/test_run.py b/tests/test_CodeEntropy/test_run.py index abd8c27..42a6232 100644 --- a/tests/test_CodeEntropy/test_run.py +++ b/tests/test_CodeEntropy/test_run.py @@ -513,6 +513,183 @@ def test_run_entropy_workflow_missing_selection_string(self): with self.assertRaisesRegex(ValueError, "Missing 'selection_string' argument."): run_manager.run_entropy_workflow() + @patch("CodeEntropy.run.EntropyManager") + @patch("CodeEntropy.run.GroupMolecules") + @patch("CodeEntropy.run.LevelManager") + @patch("CodeEntropy.run.AnalysisFromFunction") + @patch("CodeEntropy.run.mda.Merge") + @patch("CodeEntropy.run.mda.Universe") + def test_merges_forcefile_correctly( + self, MockUniverse, MockMerge, MockAnalysis, *_mocks + ): + """ + Ensure that coordinates and forces are merged correctly + when a force file is provided. + """ + run_manager = RunManager("mock/job001") + mock_logger = MagicMock() + run_manager._logging_config = MagicMock( + setup_logging=MagicMock(return_value=mock_logger) + ) + run_manager._config_manager = MagicMock() + run_manager._data_logger = MagicMock() + run_manager.show_splash = MagicMock() + + args = MagicMock( + top_traj_file=["topol.tpr", "traj.xtc"], + force_file="forces.xtc", + file_format="xtc", + selection_string="all", + verbose=False, + output_file="output.json", + kcal_force_units=False, + ) + run_manager._config_manager.load_config.return_value = {"run1": {}} + parser = run_manager._config_manager.setup_argparse.return_value + parser.parse_known_args.return_value = (args, []) + run_manager._config_manager.merge_configs.return_value = args + run_manager._config_manager.input_parameters_validation = MagicMock() + + mock_u, mock_u_force = MagicMock(), MagicMock() + MockUniverse.side_effect = [mock_u, mock_u_force] + mock_atoms, mock_atoms_force = MagicMock(), MagicMock() + mock_u.select_atoms.return_value = mock_atoms + mock_u_force.select_atoms.return_value = mock_atoms_force + + coords, forces = np.random.rand(2, 3, 3), np.random.rand(2, 3, 3) + MockAnalysis.side_effect = [ + MagicMock( + run=MagicMock(return_value=MagicMock(results={"timeseries": coords})) + ), + MagicMock( + run=MagicMock(return_value=MagicMock(results={"timeseries": forces})) + ), + ] + mock_merge = MagicMock() + MockMerge.return_value = mock_merge + + run_manager.run_entropy_workflow() + + MockUniverse.assert_any_call("topol.tpr", ["traj.xtc"], format="xtc") + MockUniverse.assert_any_call("topol.tpr", "forces.xtc", format="xtc") + MockMerge.assert_called_once_with(mock_atoms) + mock_merge.load_new.assert_called_once_with(coords, forces=forces) + self.assertEqual(mock_logger.debug.call_count, 3) + + @patch("CodeEntropy.run.EntropyManager") + @patch("CodeEntropy.run.GroupMolecules") + @patch("CodeEntropy.run.LevelManager") + @patch("CodeEntropy.run.AnalysisFromFunction") + @patch("CodeEntropy.run.mda.Merge") + @patch("CodeEntropy.run.mda.Universe") + def test_converts_kcal_to_kj(self, MockUniverse, MockMerge, MockAnalysis, *_mocks): + """ + Ensure that forces are scaled by 4.184 when kcal_force_units=True. + """ + run_manager = RunManager("mock/job001") + mock_logger = MagicMock() + run_manager._logging_config = MagicMock( + setup_logging=MagicMock(return_value=mock_logger) + ) + run_manager._config_manager = MagicMock() + run_manager._data_logger = MagicMock() + run_manager.show_splash = MagicMock() + + args = MagicMock( + top_traj_file=["topol.tpr", "traj.xtc"], + force_file="forces.xtc", + file_format="xtc", + selection_string="all", + verbose=False, + output_file="output.json", + kcal_force_units=True, + ) + run_manager._config_manager.load_config.return_value = {"run1": {}} + parser = run_manager._config_manager.setup_argparse.return_value + parser.parse_known_args.return_value = (args, []) + run_manager._config_manager.merge_configs.return_value = args + run_manager._config_manager.input_parameters_validation = MagicMock() + + mock_u, mock_u_force = MagicMock(), MagicMock() + MockUniverse.side_effect = [mock_u, mock_u_force] + mock_atoms, mock_atoms_force = MagicMock(), MagicMock() + mock_u.select_atoms.return_value = mock_atoms + mock_u_force.select_atoms.return_value = mock_atoms_force + + coords = np.random.rand(2, 3, 3) + forces = np.random.rand(2, 3, 3) + forces_orig = forces.copy() + MockAnalysis.side_effect = [ + MagicMock( + run=MagicMock(return_value=MagicMock(results={"timeseries": coords})) + ), + MagicMock( + run=MagicMock(return_value=MagicMock(results={"timeseries": forces})) + ), + ] + mock_merge = MagicMock() + MockMerge.return_value = mock_merge + + run_manager.run_entropy_workflow() + _, kwargs = mock_merge.load_new.call_args + np.testing.assert_allclose(kwargs["forces"], forces_orig * 4.184) + + @patch("CodeEntropy.run.EntropyManager") + @patch("CodeEntropy.run.GroupMolecules") + @patch("CodeEntropy.run.LevelManager") + @patch("CodeEntropy.run.AnalysisFromFunction") + @patch("CodeEntropy.run.mda.Merge") + @patch("CodeEntropy.run.mda.Universe") + def test_logs_debug_messages(self, MockUniverse, MockMerge, MockAnalysis, *_mocks): + """ + Ensure that loading and merging steps produce debug logs. + """ + run_manager = RunManager("mock/job001") + mock_logger = MagicMock() + run_manager._logging_config = MagicMock( + setup_logging=MagicMock(return_value=mock_logger) + ) + run_manager._config_manager = MagicMock() + run_manager._data_logger = MagicMock() + run_manager.show_splash = MagicMock() + + args = MagicMock( + top_traj_file=["topol.tpr", "traj.xtc"], + force_file="forces.xtc", + file_format="xtc", + selection_string="all", + verbose=False, + output_file="output.json", + kcal_force_units=False, + ) + run_manager._config_manager.load_config.return_value = {"run1": {}} + parser = run_manager._config_manager.setup_argparse.return_value + parser.parse_known_args.return_value = (args, []) + run_manager._config_manager.merge_configs.return_value = args + run_manager._config_manager.input_parameters_validation = MagicMock() + + mock_u, mock_u_force = MagicMock(), MagicMock() + MockUniverse.side_effect = [mock_u, mock_u_force] + mock_atoms, mock_atoms_force = MagicMock(), MagicMock() + mock_u.select_atoms.return_value = mock_atoms + mock_u_force.select_atoms.return_value = mock_atoms_force + + arr = np.random.rand(2, 3, 3) + MockAnalysis.side_effect = [ + MagicMock( + run=MagicMock(return_value=MagicMock(results={"timeseries": arr})) + ), + MagicMock( + run=MagicMock(return_value=MagicMock(results={"timeseries": arr})) + ), + ] + MockMerge.return_value = MagicMock() + + run_manager.run_entropy_workflow() + debug_msgs = [c[0][0] for c in mock_logger.debug.call_args_list] + self.assertTrue(any("forces.xtc" in m for m in debug_msgs)) + self.assertTrue(any("Merging forces" in m for m in debug_msgs)) + @patch("CodeEntropy.run.AnalysisFromFunction") @patch("CodeEntropy.run.mda.Merge") def test_new_U_select_frame(self, MockMerge, MockAnalysisFromFunction):