Skip to content
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

Not only querying, but also modifying system parameters #18

Merged
merged 14 commits into from
May 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"id": "3a4fdeed",
"metadata": {},
"source": [
"## Querying Charges and Other Parameters\n",
"## Querying and Modifying Charges and Other Parameters\n",
"\n",
"Sometimes you want to inspect the charges or other parameters of the particles or bonds in a System. Force field parameters are stored in the Force objects added to a System. As an example, let's load a PDB file and model it using the Amber14 force field."
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"id": "9323aaae",
"metadata": {},
"outputs": [],
Expand All @@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "1734190f",
"metadata": {},
"outputs": [],
Expand All @@ -53,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "bf38fc9a",
"metadata": {},
"outputs": [],
Expand All @@ -76,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"id": "933928f9",
"metadata": {},
"outputs": [
Expand All @@ -98,12 +98,84 @@
" if particle1 == 0 or particle2 == 0:\n",
" print(f'Particles ({particle1}, {particle2}), length = {length}, k = {k}')"
]
},
{
"cell_type": "markdown",
"id": "50f5157c",
"metadata": {},
"source": [
"In some cases you may want to modify those parameters to make a bond behave differently from what the `ForceField` assigned.\n",
"We show you here that to modify these parameters are also easy."
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "cd5396c5",
"metadata": {},
"source": [
"Let's say we would want to modify the force constant of the bond connecting particle 1 and 0 to a new number."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "086c7629",
"metadata": {},
"outputs": [],
"source": [
"for i in range(bonded.getNumBonds()):\n",
" particle1, particle2, length, k = bonded.getBondParameters(i)\n",
" if particle1 == 1 and particle2 == 0:\n",
" bonded.setBondParameters(i, particle1, particle2, length, 2666 * unit.kilojoules_per_mole/unit.nanometer**2)"
]
},
{
"cell_type": "markdown",
"id": "8f9728ad",
"metadata": {},
"source": [
"Now if you query again you can see new parameters."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "68498ff5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Particles (4, 0), length = 0.1471 nm, k = 307105.5999999999 kJ/(nm**2 mol)\n",
"Particles (1, 0), length = 0.101 nm, k = 2666.0 kJ/(nm**2 mol)\n",
"Particles (2, 0), length = 0.101 nm, k = 363171.19999999995 kJ/(nm**2 mol)\n",
"Particles (3, 0), length = 0.101 nm, k = 363171.19999999995 kJ/(nm**2 mol)\n"
]
}
],
"source": [
"for i in range(bonded.getNumBonds()):\n",
" particle1, particle2, length, k = bonded.getBondParameters(i)\n",
" if particle1 == 0 or particle2 == 0:\n",
" print(f'Particles ({particle1}, {particle2}), length = {length}, k = {k}')"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "47729e2e",
"metadata": {},
"source": [
"Modifying `Force` objects will affect any new `Simulations` or `Contexts` you create, but it will have no effect on ones that already exist. \n",
"If you want your modifications to apply to an existing `Simulation`, you can copy them over by calling `bonded.updateParametersInContext(simulation.context)`."
]
}
],
"metadata": {
"tags": ["force field", "inspection", "forces"],
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -117,8 +189,13 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
}
"version": "3.11.3"
},
"tags": [
"force field",
"inspection",
"forces"
]
},
"nbformat": 4,
"nbformat_minor": 5
Expand Down