Skip to content

Commit

Permalink
Some tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Dec 22, 2024
1 parent 6fb5ddf commit 0fc1dee
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 2 deletions.
99 changes: 99 additions & 0 deletions docs/contents/user/tools/element/group/get_group_type.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c55e0a44-c9d9-4229-9a9b-96ecd1ed9b8d",
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "cc4d7152-a00a-4654-be50-b421e01f584d",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "83bdfff8a1d1405796d60a09d881a850",
"version_major": 2,
"version_minor": 0
},
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import molsysmt as msm"
]
},
{
"cell_type": "markdown",
"id": "e203abd4-cf31-4dc5-afa7-b3d980bd30a9",
"metadata": {},
"source": [
"# Get group type\n",
"\n",
"In construction."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f5ae9d14-a25f-40cd-b895-44aade003898",
"metadata": {},
"outputs": [],
"source": [
"molsys = msm.convert(msm.systems['chicken villin HP35']['chicken_villin_HP35_solvated.h5msm'])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6de8ddad-1b3d-447a-974d-eed4b4154169",
"metadata": {},
"outputs": [],
"source": [
"types = msm.element.group.get_group_type(molsys, element='group', selection='all')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "877cd452-492f-4bf9-9ef5-d2ded6dcf3dd",
"metadata": {},
"outputs": [],
"source": [
"types2 = msm.element.group.get_group_type(molsys, element='group', selection='all', redefine_types=True)"
]
}
],
"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.11.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
19 changes: 19 additions & 0 deletions docs/contents/user/tools/element/group/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Molecule


| | |
| :--- | :--- |
| [Get bonded_atom_pairs](get_bonded_atom_pairs.ipynb) | Getting the bonded atom pairs in a group |
| [Get group_type](get_group_type.ipynb) | Getting the group type |
| [Is group_type](is_group_type.ipynb) | Is group type |

```{eval-rst}
.. toctree::
:maxdepth: 2
:hidden:
get_bonded_atom_pairs.ipynb
get_group_type.ipynb
is_group_type.ipynb
```
161 changes: 161 additions & 0 deletions docs/contents/user/tools/element/group/is_group_type.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c55e0a44-c9d9-4229-9a9b-96ecd1ed9b8d",
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "cc4d7152-a00a-4654-be50-b421e01f584d",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3deb7193f94343f7b759d5efefa6b0e1",
"version_major": 2,
"version_minor": 0
},
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import molsysmt as msm"
]
},
{
"cell_type": "markdown",
"id": "e203abd4-cf31-4dc5-afa7-b3d980bd30a9",
"metadata": {},
"source": [
"# Is group type\n",
"\n",
"In construction."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d02da3fc-babc-46bd-ac67-824f2ea2588a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"msm.element.group.is_group_type('water')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c0af30b4-d6a0-49a8-a134-8f64fcfc6140",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"msm.element.group.is_group_type('lipid')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "835416a3-0584-4f83-afdf-04be79129295",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"msm.element.group.is_group_type('terminal capping')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "bc8b7376-9025-4405-a51e-4521638e56d0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"msm.element.group.is_group_type('amino acid')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "46baffcf-b621-4b7e-ab7f-8b55721c93d0",
"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.11.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 2 additions & 2 deletions molsysmt/element/group/get_group_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def get_group_type(molecular_system, element='atom', selection='all', redefine_t
unique_group_names = np.unique(group_names_from_group)
aux_dict = {}
for name in unique_group_names:
tmp_group_type = _get_group_type_from_group_name(name)
tmp_group_type = get_group_type_from_group_name(name)
if tmp_group_type == 'small molecule':
if _small_molecule_is_amino_acid(molecular_system, group_index):
tmp_group_type = 'amino acid'
aux_dict[name] = _get_group_type_from_group_name(name)
aux_dict[name] = get_group_type_from_group_name(name)

output = [aux_dict[ii] for ii in group_names_from_group]

Expand Down
39 changes: 39 additions & 0 deletions tests/element/group/test_get_group_type_from_molsysmt_MolSys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Unit and regression test for the get_form module of the molsysmt package.
"""

# Import package, test suite, and other packages as needed
import molsysmt as msm
from molsysmt import systems
import numpy as np

def test_get_group_type_from_molsysmt_MolSys_1():

molsys = msm.convert(systems['chicken villin HP35']['chicken_villin_HP35_solvated.h5msm'])
types = msm.element.group.get_group_type(molsys, element='group', selection='all')
assert len(types) == 1273
assert types[0] == 'terminal capping'
assert all(np.array(types[1:37])=='amino acid')
assert types[37] == 'terminal capping'
assert all(np.array(types[38:-2])=='water')
assert all(np.array(types[-2:])=='ion')

def test_get_group_type_from_molsysmt_MolSys_2():

molsys = msm.convert(systems['chicken villin HP35']['chicken_villin_HP35_solvated.h5msm'])
types = msm.element.group.get_group_type(molsys, element='atom', selection='all', redefine_types=True)

assert all(np.array(types[:6])=='terminal capping')
assert all(np.array(types[6:599])=='amino acid')
assert all(np.array(types[599:605])=='terminal capping')
assert all(np.array(types[605:4304])=='water')
assert all(np.array(types[-2:])=='ion')

def test_get_group_type_from_molsysmt_MolSys_3():

molsys = msm.convert(systems['chicken villin HP35']['chicken_villin_HP35_solvated.h5msm'])
types = msm.element.group.get_group_type(molsys, element='group', selection='all')
types2 = msm.element.group.get_group_type(molsys, element='group', selection='all', redefine_types=True)

assert types==types2

35 changes: 35 additions & 0 deletions tests/element/group/test_is_group_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Unit and regression test for the get_form module of the molsysmt package.
"""

# Import package, test suite, and other packages as needed
import molsysmt as msm
from molsysmt import systems
import numpy as np

def test_is_group_type_molsysmt_MolSys_1():

assert msm.element.group.is_group_type('water')
assert msm.element.group.is_group_type('ion')
assert msm.element.group.is_group_type('small molecule')
assert msm.element.group.is_group_type('amino acid')
assert msm.element.group.is_group_type('terminal capping')
assert msm.element.group.is_group_type('nucleotide')
assert msm.element.group.is_group_type('lipid')
assert msm.element.group.is_group_type('saccharide')
assert msm.element.group.is_group_type('oligosaccharide')
assert msm.element.group.is_group_type('papa')==False


def test_is_group_type_molsysmt_MolSys_2():

assert msm.element.group.is_group_type('waters')
assert msm.element.group.is_group_type('ions')
assert msm.element.group.is_group_type('small molecules')
assert msm.element.group.is_group_type('amino acids')
assert msm.element.group.is_group_type('terminal cappings')
assert msm.element.group.is_group_type('nucleotides')
assert msm.element.group.is_group_type('lipids')
assert msm.element.group.is_group_type('saccharides')
assert msm.element.group.is_group_type('oligosaccharides')

File renamed without changes.

0 comments on commit 0fc1dee

Please sign in to comment.