From 57661566df0a38717064077497eb191315c130fa Mon Sep 17 00:00:00 2001 From: StephMcCallum Date: Fri, 21 Jun 2024 18:06:51 -0700 Subject: [PATCH 01/11] adding comments for things to do --- grits/coarsegrain.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index 7d7fd2f..7c249e3 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -727,6 +727,8 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): new_snap = gsd.hoomd.Frame() position = [] mass = [] + #make an empty list for forces here + orientation = [] if self.aniso_beads else None f_box = freud.Box.from_box(s.configuration.box) unwrap_pos = f_box.unwrap( @@ -738,6 +740,9 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): mass += [ sum(s.particles.mass[x]) * self.mass_scale for x in inds ] + + #do the force calculation here + if self.aniso_beads: for x in inds: masses = s.particles.mass[x] * self.mass_scale From 00a468161aa6b9c1044fa8afa87b5b881d8af005 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Jun 2024 01:08:49 +0000 Subject: [PATCH 02/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- grits/coarsegrain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index 7c249e3..bcd691b 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -727,7 +727,7 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): new_snap = gsd.hoomd.Frame() position = [] mass = [] - #make an empty list for forces here + # make an empty list for forces here orientation = [] if self.aniso_beads else None f_box = freud.Box.from_box(s.configuration.box) @@ -741,8 +741,8 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): sum(s.particles.mass[x]) * self.mass_scale for x in inds ] - #do the force calculation here - + # do the force calculation here + if self.aniso_beads: for x in inds: masses = s.particles.mass[x] * self.mass_scale From 365d643ec02cc094f3a8ff479387e08545302763 Mon Sep 17 00:00:00 2001 From: StephMcCallum Date: Fri, 21 Jun 2024 18:19:14 -0700 Subject: [PATCH 03/11] Adding force list --- grits/coarsegrain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index 7c249e3..01abb7a 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -728,7 +728,7 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): position = [] mass = [] #make an empty list for forces here - + forces = [] orientation = [] if self.aniso_beads else None f_box = freud.Box.from_box(s.configuration.box) unwrap_pos = f_box.unwrap( @@ -742,7 +742,7 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): ] #do the force calculation here - + if self.aniso_beads: for x in inds: masses = s.particles.mass[x] * self.mass_scale From 8b51bddd623c61a5e0b114238b5ec916befed229 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Jun 2024 01:20:53 +0000 Subject: [PATCH 04/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- grits/coarsegrain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index 01abb7a..0d177d3 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -727,7 +727,7 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): new_snap = gsd.hoomd.Frame() position = [] mass = [] - #make an empty list for forces here + # make an empty list for forces here forces = [] orientation = [] if self.aniso_beads else None f_box = freud.Box.from_box(s.configuration.box) @@ -741,7 +741,7 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): sum(s.particles.mass[x]) * self.mass_scale for x in inds ] - #do the force calculation here + # do the force calculation here if self.aniso_beads: for x in inds: From 83c887a25acfd3ada4078a94c4f4fa1adb7b46b2 Mon Sep 17 00:00:00 2001 From: StephMcCallum Date: Tue, 25 Jun 2024 13:33:53 -0700 Subject: [PATCH 05/11] Adding test velocity calculation --- grits/coarsegrain.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index 0d177d3..19df96c 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -728,7 +728,9 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): position = [] mass = [] # make an empty list for forces here - forces = [] + net_force = [] + # make an empty list for velocity + velocity = [] orientation = [] if self.aniso_beads else None f_box = freud.Box.from_box(s.configuration.box) unwrap_pos = f_box.unwrap( @@ -742,6 +744,8 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): ] # do the force calculation here + # do the velocity calculation here + velocity += [np.mean(s.particles.velocity[x], axis=0) for x in inds] if self.aniso_beads: for x in inds: From eb743e7c3ff568d5ee9f4c1f678567789612795f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:55:13 +0000 Subject: [PATCH 06/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- grits/coarsegrain.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index 19df96c..3c68c00 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -745,7 +745,9 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): # do the force calculation here # do the velocity calculation here - velocity += [np.mean(s.particles.velocity[x], axis=0) for x in inds] + velocity += [ + np.mean(s.particles.velocity[x], axis=0) for x in inds + ] if self.aniso_beads: for x in inds: From b0f80dc7eeff753c271bb3ea99ee6de3c14198b1 Mon Sep 17 00:00:00 2001 From: Steph McCallum Date: Thu, 8 Aug 2024 15:45:24 -0600 Subject: [PATCH 07/11] Adding force calculation and test file. Need to update method of adding the forces to gsd log file. --- Test run.ipynb | 247 +++++++++++++++++++++++++++++++++++++++++++ grits/coarsegrain.py | 12 ++- 2 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 Test run.ipynb diff --git a/Test run.ipynb b/Test run.ipynb new file mode 100644 index 0000000..449a990 --- /dev/null +++ b/Test run.ipynb @@ -0,0 +1,247 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "86a0a551-a4df-4664-b230-63c0b6577256", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/stephaniemccallum/miniforge3/envs/grits/lib/python3.12/site-packages/mdtraj/formats/__init__.py:13: DeprecationWarning: 'xdrlib' is deprecated and slated for removal in Python 3.13\n", + " from mdtraj.formats.trr import TRRTrajectoryFile\n", + "/Users/stephaniemccallum/miniforge3/envs/grits/lib/python3.12/site-packages/foyer/forcefield.py:33: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html\n", + " from pkg_resources import iter_entry_points, resource_filename\n", + "/Users/stephaniemccallum/miniforge3/envs/grits/lib/python3.12/site-packages/pkg_resources/__init__.py:3144: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.\n", + "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n", + " declare_namespace(pkg)\n", + "/Users/stephaniemccallum/miniforge3/envs/grits/lib/python3.12/site-packages/lark/utils.py:163: DeprecationWarning: module 'sre_parse' is deprecated\n", + " import sre_parse\n", + "/Users/stephaniemccallum/miniforge3/envs/grits/lib/python3.12/site-packages/lark/utils.py:164: DeprecationWarning: module 'sre_constants' is deprecated\n", + " import sre_constants\n", + "/Users/stephaniemccallum/miniforge3/envs/grits/lib/python3.12/site-packages/mbuild/packing.py:23: DeprecationWarning: Use shutil.which instead of find_executable\n", + " PACKMOL = find_executable(\"packmol\")\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "import mbuild as mb\n", + "\n", + "from grits import CG_System\n", + "from grits.utils import amber_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "52fd0a7c-35af-43b2-874f-a6b52fc03d65", + "metadata": {}, + "outputs": [], + "source": [ + "PPS_smiles = \"c1ccc(S)cc1\"\n", + "a = mb.load(PPS_smiles, smiles=True)\n", + "#a.visualize().show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31b14f3c-43d4-4642-953b-114b96bfa950", + "metadata": {}, + "outputs": [], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2139bf63-20f2-4675-9eac-d20dddf9e328", + "metadata": {}, + "outputs": [], + "source": [ + "pwd" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d6285f42-272c-4206-b738-fa3cb3688626", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Added 6 hydrogens.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/stephaniemccallum/Desktop/cmelab/forks/grits/grits/coarsegrain.py:192: UserWarning: Some atoms have been left out of coarse-graining!\n", + " warn(f\"Some atoms have been left out of coarse-graining!\")\n" + ] + } + ], + "source": [ + "gsdfile = \"/Users/stephaniemccallum/Desktop/cmelab/forks/grits/pps_trajectory_kT_2.0.gsd\"\n", + "system = CG_System(\n", + " gsdfile,\n", + " add_hydrogens = True,\n", + " beads={\"_A\": PPS_smiles},\n", + " conversion_dict=amber_dict\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "9660225b-93e6-49b8-9d31-5786ae97e187", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1, 7, 3)\n" + ] + }, + { + "ename": "ValueError", + "evalue": "GSD can only write 1 or 2 dimensional arrays: log/net_force", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[4], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m cg_gsd \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPPS-cg.gsd\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 2\u001b[0m \u001b[43msystem\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msave\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcg_gsd\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Desktop/cmelab/forks/grits/grits/coarsegrain.py:799\u001b[0m, in \u001b[0;36mCG_System.save\u001b[0;34m(self, cg_gsdfile, start, stop, stride)\u001b[0m\n\u001b[1;32m 797\u001b[0m new_snap\u001b[38;5;241m.\u001b[39mparticles\u001b[38;5;241m.\u001b[39morientation \u001b[38;5;241m=\u001b[39m orientation\n\u001b[1;32m 798\u001b[0m new_snap \u001b[38;5;241m=\u001b[39m identify_snapshot_connections(new_snap)\n\u001b[0;32m--> 799\u001b[0m \u001b[43mnew\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mappend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnew_snap\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/miniforge3/envs/grits/lib/python3.12/site-packages/gsd/hoomd.py:787\u001b[0m, in \u001b[0;36mHOOMDTrajectory.append\u001b[0;34m(self, frame)\u001b[0m\n\u001b[1;32m 785\u001b[0m \u001b[38;5;66;03m# write log data\u001b[39;00m\n\u001b[1;32m 786\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m log, data \u001b[38;5;129;01min\u001b[39;00m frame\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mitems():\n\u001b[0;32m--> 787\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfile\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwrite_chunk\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mlog/\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mlog\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 789\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfile\u001b[38;5;241m.\u001b[39mend_frame()\n", + "File \u001b[0;32m~/miniforge3/envs/grits/lib/python3.12/site-packages/gsd/fl.pyx:569\u001b[0m, in \u001b[0;36mgsd.fl.GSDFile.write_chunk\u001b[0;34m()\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: GSD can only write 1 or 2 dimensional arrays: log/net_force" + ] + } + ], + "source": [ + "cg_gsd = \"PPS-cg.gsd\"\n", + "system.save(cg_gsd)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "90ecc7df-c73d-489d-8053-143459f91313", + "metadata": {}, + "outputs": [], + "source": [ + "import gsd.hoomd\n", + "\n", + "traj = gsd.hoomd.open(gsdfile)\n", + "snap = traj[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a434d67-2d79-4ebf-b400-709a5baa8c66", + "metadata": {}, + "outputs": [], + "source": [ + "inds = [1, 2, 3, 4]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5474c6f6-3fad-49b8-90cd-6142b870b379", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "\n", + "np.add.reduce(snap.log[\"particles/md/pair/LJ/forces\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d0906fe-0023-4b98-9cdb-97f133843a8b", + "metadata": {}, + "outputs": [], + "source": [ + "snap.log[\"particles/md/pair/LJ/forces\"].shape" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "474275ce-74a4-498c-b5e6-acaf9b26ab3e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "36fbdb7b-7449-4cbe-bc1e-40f5f158b1dd", + "metadata": {}, + "outputs": [], + "source": [ + "snap.particles.velocity" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ddec25f-8367-410a-91f1-e18082affb6f", + "metadata": {}, + "outputs": [], + "source": [ + "dir(snap)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "30657571-9928-45af-8e87-ca88a670b7f2", + "metadata": {}, + "outputs": [], + "source": [ + "snap.log" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7f765cf4-4e7d-41a0-950a-71e013b88b19", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index 3c68c00..2265b28 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -727,8 +727,11 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): new_snap = gsd.hoomd.Frame() position = [] mass = [] - # make an empty list for forces here - net_force = [] + # make an empty lists for forces here + traj_lj_forces = [] + traj_bond_forces = [] + traj_angle_forces = [] + traj_dihedral_forces = [] # make an empty list for velocity velocity = [] orientation = [] if self.aniso_beads else None @@ -744,6 +747,7 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): ] # do the force calculation here + traj_lj_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds])) # do the velocity calculation here velocity += [ np.mean(s.particles.velocity[x], axis=0) for x in inds @@ -768,7 +772,7 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): position = np.vstack(position) images = f_box.get_images(position) position = f_box.wrap(position) - + print(np.array(traj_lj_forces).shape) new_snap.configuration.box = s.configuration.box new_snap.configuration.step = s.configuration.step new_snap.particles.N = len(typeid) @@ -777,6 +781,8 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): new_snap.particles.typeid = typeid.astype(int) new_snap.particles.types = types new_snap.particles.mass = mass + new_snap.particles.velocity = velocity + new_snap.log["net_force"] = np.array(traj_lj_forces) if N_bonds > 0: new_snap.bonds.N = N_bonds From 2a4194f48ca7a40adc16f567081206c633bf45f6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 21:48:19 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- grits/coarsegrain.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index 2265b28..66b18b9 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -747,7 +747,11 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): ] # do the force calculation here - traj_lj_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds])) + traj_lj_forces.append( + np.add.reduce( + s.log["particles/md/pair/LJ/forces"][inds] + ) + ) # do the velocity calculation here velocity += [ np.mean(s.particles.velocity[x], axis=0) for x in inds From 6d35f1a843ff8a3e177a793f2f5b768c65339079 Mon Sep 17 00:00:00 2001 From: Steph McCallum Date: Mon, 12 Aug 2024 09:43:56 -0600 Subject: [PATCH 09/11] Changing axis of reduce function and adding squeeze function for a temporary fix to remove third dimension of array created from reduce function. --- Test run.ipynb | 286 +++++++++++++++++++++++++++++++------------ grits/coarsegrain.py | 4 +- 2 files changed, 213 insertions(+), 77 deletions(-) diff --git a/Test run.ipynb b/Test run.ipynb index 449a990..81cae0f 100644 --- a/Test run.ipynb +++ b/Test run.ipynb @@ -4,7 +4,9 @@ "cell_type": "code", "execution_count": 1, "id": "86a0a551-a4df-4664-b230-63c0b6577256", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stderr", @@ -46,26 +48,6 @@ "#a.visualize().show()" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "31b14f3c-43d4-4642-953b-114b96bfa950", - "metadata": {}, - "outputs": [], - "source": [ - "ls" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2139bf63-20f2-4675-9eac-d20dddf9e328", - "metadata": {}, - "outputs": [], - "source": [ - "pwd" - ] - }, { "cell_type": "code", "execution_count": 3, @@ -95,7 +77,7 @@ " add_hydrogens = True,\n", " beads={\"_A\": PPS_smiles},\n", " conversion_dict=amber_dict\n", - ")" + ")\n" ] }, { @@ -108,21 +90,107 @@ "name": "stdout", "output_type": "stream", "text": [ - "(1, 7, 3)\n" - ] - }, - { - "ename": "ValueError", - "evalue": "GSD can only write 1 or 2 dimensional arrays: log/net_force", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[4], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m cg_gsd \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPPS-cg.gsd\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 2\u001b[0m \u001b[43msystem\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msave\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcg_gsd\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Desktop/cmelab/forks/grits/grits/coarsegrain.py:799\u001b[0m, in \u001b[0;36mCG_System.save\u001b[0;34m(self, cg_gsdfile, start, stop, stride)\u001b[0m\n\u001b[1;32m 797\u001b[0m new_snap\u001b[38;5;241m.\u001b[39mparticles\u001b[38;5;241m.\u001b[39morientation \u001b[38;5;241m=\u001b[39m orientation\n\u001b[1;32m 798\u001b[0m new_snap \u001b[38;5;241m=\u001b[39m identify_snapshot_connections(new_snap)\n\u001b[0;32m--> 799\u001b[0m \u001b[43mnew\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mappend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnew_snap\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/miniforge3/envs/grits/lib/python3.12/site-packages/gsd/hoomd.py:787\u001b[0m, in \u001b[0;36mHOOMDTrajectory.append\u001b[0;34m(self, frame)\u001b[0m\n\u001b[1;32m 785\u001b[0m \u001b[38;5;66;03m# write log data\u001b[39;00m\n\u001b[1;32m 786\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m log, data \u001b[38;5;129;01min\u001b[39;00m frame\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mitems():\n\u001b[0;32m--> 787\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfile\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwrite_chunk\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mlog/\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mlog\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 789\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfile\u001b[38;5;241m.\u001b[39mend_frame()\n", - "File \u001b[0;32m~/miniforge3/envs/grits/lib/python3.12/site-packages/gsd/fl.pyx:569\u001b[0m, in \u001b[0;36mgsd.fl.GSDFile.write_chunk\u001b[0;34m()\u001b[0m\n", - "\u001b[0;31mValueError\u001b[0m: GSD can only write 1 or 2 dimensional arrays: log/net_force" + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n", + "(300, 3)\n" ] } ], @@ -133,7 +201,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "90ecc7df-c73d-489d-8053-143459f91313", "metadata": {}, "outputs": [], @@ -146,81 +214,147 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "7a434d67-2d79-4ebf-b400-709a5baa8c66", "metadata": {}, "outputs": [], "source": [ - "inds = [1, 2, 3, 4]" + "inds = [0,1,2,3]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "5474c6f6-3fad-49b8-90cd-6142b870b379", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([-0.58440879, -0.72004115, -0.20885618])" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import numpy as np\n", "\n", - "np.add.reduce(snap.log[\"particles/md/pair/LJ/forces\"])" + "np.add.reduce(snap.log[\"particles/md/pair/LJ/forces\"][inds])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "4d0906fe-0023-4b98-9cdb-97f133843a8b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[-0.59678146 -0.7094508 -0.20883539]\n", + " [ 0. 0. 0. ]\n", + " [ 0. 0. 0. ]\n", + " ...\n", + " [-0.23439395 -0.89780405 -0.28628996]\n", + " [ 0. 0. 0. ]\n", + " [ 0. 0. 0. ]]\n" + ] + } + ], "source": [ - "snap.log[\"particles/md/pair/LJ/forces\"].shape" + "print(snap.log[\"particles/md/pair/LJ/forces\"])" ] }, { "cell_type": "code", - "execution_count": null, - "id": "474275ce-74a4-498c-b5e6-acaf9b26ab3e", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "36fbdb7b-7449-4cbe-bc1e-40f5f158b1dd", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 0.46751893, -0.4557764 , 1.5517997 ],\n", + " [ 1.2661922 , 2.2942452 , 2.3974137 ],\n", + " [ 0.99841857, -0.54276377, -0.38419962],\n", + " ...,\n", + " [-0.16005144, 0.94953936, -1.093895 ],\n", + " [ 0.6594045 , -1.5998036 , -1.1851496 ],\n", + " [-0.8315832 , 1.2608055 , 0.19617926]], dtype=float32)" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "snap.particles.velocity" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "6ddec25f-8367-410a-91f1-e18082affb6f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['__class__',\n", + " '__delattr__',\n", + " '__dict__',\n", + " '__dir__',\n", + " '__doc__',\n", + " '__eq__',\n", + " '__format__',\n", + " '__ge__',\n", + " '__getattribute__',\n", + " '__getstate__',\n", + " '__gt__',\n", + " '__hash__',\n", + " '__init__',\n", + " '__init_subclass__',\n", + " '__le__',\n", + " '__lt__',\n", + " '__module__',\n", + " '__ne__',\n", + " '__new__',\n", + " '__reduce__',\n", + " '__reduce_ex__',\n", + " '__repr__',\n", + " '__setattr__',\n", + " '__sizeof__',\n", + " '__slotnames__',\n", + " '__str__',\n", + " '__subclasshook__',\n", + " '__weakref__',\n", + " '_valid_state',\n", + " 'angles',\n", + " 'bonds',\n", + " 'configuration',\n", + " 'constraints',\n", + " 'dihedrals',\n", + " 'impropers',\n", + " 'log',\n", + " 'pairs',\n", + " 'particles',\n", + " 'state',\n", + " 'validate']" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "dir(snap)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "30657571-9928-45af-8e87-ca88a670b7f2", - "metadata": {}, - "outputs": [], - "source": [ - "snap.log" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7f765cf4-4e7d-41a0-950a-71e013b88b19", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index 2265b28..0871270 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -729,6 +729,7 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): mass = [] # make an empty lists for forces here traj_lj_forces = [] + traj_lj_forces_temp = [] traj_bond_forces = [] traj_angle_forces = [] traj_dihedral_forces = [] @@ -747,7 +748,8 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): ] # do the force calculation here - traj_lj_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds])) + traj_lj_forces_temp.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) + traj_lj_forces = np.squeeze(traj_lj_forces_temp,axis=0) # do the velocity calculation here velocity += [ np.mean(s.particles.velocity[x], axis=0) for x in inds From 660bf1ce62866ade3a559e3bffeb4186c2e7e160 Mon Sep 17 00:00:00 2001 From: Steph McCallum Date: Tue, 13 Aug 2024 14:47:07 -0600 Subject: [PATCH 10/11] Updating net force calculation --- Test run.ipynb | 110 +------------------------------------------ grits/coarsegrain.py | 26 +++++----- 2 files changed, 14 insertions(+), 122 deletions(-) diff --git a/Test run.ipynb b/Test run.ipynb index 81cae0f..d5bfbff 100644 --- a/Test run.ipynb +++ b/Test run.ipynb @@ -85,115 +85,7 @@ "execution_count": 4, "id": "9660225b-93e6-49b8-9d31-5786ae97e187", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n", - "(300, 3)\n" - ] - } - ], + "outputs": [], "source": [ "cg_gsd = \"PPS-cg.gsd\"\n", "system.save(cg_gsd)" diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index a3eb1da..f8f1b91 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -729,10 +729,10 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): mass = [] # make an empty lists for forces here traj_lj_forces = [] - traj_lj_forces_temp = [] traj_bond_forces = [] traj_angle_forces = [] traj_dihedral_forces = [] + net_force = [] # make an empty list for velocity velocity = [] orientation = [] if self.aniso_beads else None @@ -748,16 +748,15 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): ] # do the force calculation here -<<<<<<< HEAD - traj_lj_forces_temp.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) - traj_lj_forces = np.squeeze(traj_lj_forces_temp,axis=0) -======= - traj_lj_forces.append( - np.add.reduce( - s.log["particles/md/pair/LJ/forces"][inds] - ) - ) ->>>>>>> 2a4194f48ca7a40adc16f567081206c633bf45f6 + traj_lj_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) + traj_bond_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) + traj_angle_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) + traj_dihedral_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) + traj_lj_forces = np.squeeze(traj_lj_forces,axis=0) + traj_bond_forces = np.squeeze(traj_bond_forces,axis=0) + traj_angle_forces = np.squeeze(traj_angle_forces,axis=0) + traj_dihedral_forces = np.squeeze(traj_dihedral_forces,axis=0) + # do the velocity calculation here velocity += [ np.mean(s.particles.velocity[x], axis=0) for x in inds @@ -782,7 +781,8 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): position = np.vstack(position) images = f_box.get_images(position) position = f_box.wrap(position) - print(np.array(traj_lj_forces).shape) + arr = [np.array(traj_lj_forces),np.array(traj_bond_forces),np.array(traj_angle_forces),np.array(traj_dihedral_forces)] + net_force = np.add.reduce(arr) new_snap.configuration.box = s.configuration.box new_snap.configuration.step = s.configuration.step new_snap.particles.N = len(typeid) @@ -792,7 +792,7 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): new_snap.particles.types = types new_snap.particles.mass = mass new_snap.particles.velocity = velocity - new_snap.log["net_force"] = np.array(traj_lj_forces) + new_snap.log["net_force"] = np.array(net_force) if N_bonds > 0: new_snap.bonds.N = N_bonds From 13eda05e7eaf32840408c69eb9d1d440b29cab8a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Aug 2024 20:49:02 +0000 Subject: [PATCH 11/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- grits/coarsegrain.py | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/grits/coarsegrain.py b/grits/coarsegrain.py index f8f1b91..1444c07 100644 --- a/grits/coarsegrain.py +++ b/grits/coarsegrain.py @@ -748,14 +748,32 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): ] # do the force calculation here - traj_lj_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) - traj_bond_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) - traj_angle_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) - traj_dihedral_forces.append(np.add.reduce(s.log['particles/md/pair/LJ/forces'][inds],1)) - traj_lj_forces = np.squeeze(traj_lj_forces,axis=0) - traj_bond_forces = np.squeeze(traj_bond_forces,axis=0) - traj_angle_forces = np.squeeze(traj_angle_forces,axis=0) - traj_dihedral_forces = np.squeeze(traj_dihedral_forces,axis=0) + traj_lj_forces.append( + np.add.reduce( + s.log["particles/md/pair/LJ/forces"][inds], 1 + ) + ) + traj_bond_forces.append( + np.add.reduce( + s.log["particles/md/pair/LJ/forces"][inds], 1 + ) + ) + traj_angle_forces.append( + np.add.reduce( + s.log["particles/md/pair/LJ/forces"][inds], 1 + ) + ) + traj_dihedral_forces.append( + np.add.reduce( + s.log["particles/md/pair/LJ/forces"][inds], 1 + ) + ) + traj_lj_forces = np.squeeze(traj_lj_forces, axis=0) + traj_bond_forces = np.squeeze(traj_bond_forces, axis=0) + traj_angle_forces = np.squeeze(traj_angle_forces, axis=0) + traj_dihedral_forces = np.squeeze( + traj_dihedral_forces, axis=0 + ) # do the velocity calculation here velocity += [ @@ -781,7 +799,12 @@ def save(self, cg_gsdfile, start=0, stop=None, stride=1): position = np.vstack(position) images = f_box.get_images(position) position = f_box.wrap(position) - arr = [np.array(traj_lj_forces),np.array(traj_bond_forces),np.array(traj_angle_forces),np.array(traj_dihedral_forces)] + arr = [ + np.array(traj_lj_forces), + np.array(traj_bond_forces), + np.array(traj_angle_forces), + np.array(traj_dihedral_forces), + ] net_force = np.add.reduce(arr) new_snap.configuration.box = s.configuration.box new_snap.configuration.step = s.configuration.step