Skip to content

Commit

Permalink
In process to write more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Jul 4, 2024
1 parent 5470a99 commit 8121025
Show file tree
Hide file tree
Showing 11 changed files with 37,734 additions and 108 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ omit =
molsysmt/element/atom/names.py
molsysmt/element/atom/names_cg.py
molsysmt/element/chain/chain_names.py
molsysmt/native/file_tng.py
molsysmt/native/file_xtc.py

3,262 changes: 3,262 additions & 0 deletions molsysmt/data/pdb/1bnf.pdb

Large diffs are not rendered by default.

2,678 changes: 2,678 additions & 0 deletions molsysmt/data/pdb/2vgy.pdb

Large diffs are not rendered by default.

1,428 changes: 1,428 additions & 0 deletions molsysmt/data/pdb/3c0f.pdb

Large diffs are not rendered by default.

26,321 changes: 26,321 additions & 0 deletions molsysmt/data/pdb/3c8h.pdb

Large diffs are not rendered by default.

3,933 changes: 3,933 additions & 0 deletions molsysmt/data/pdb/5ip4.pdb

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions molsysmt/native/pdb_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def parse_format33(file):
elif aux.startswith('EC:'): ### EC
compnd.ec = aux[3:].strip()[:-1]
elif aux.startswith('SYNONYM:'): ### SYNONYM
compnd.synonym += [ii.strip() for ii in aux[8:].strip()[:-1].split(',')]
compnd.synonym = [ii.strip() for ii in aux[8:].strip()[:-1].split(',')]
elif aux.startswith('ENGINEERED:'): ### ENGINEERED
compnd.engineered = aux[11:].strip()[:-1]
elif aux.startswith('MUTATION:'): ### MUTATION
Expand Down Expand Up @@ -561,7 +561,10 @@ def parse_format33(file):
seqadv.database = _dict_database_name[line[24:28].strip()]
seqadv.dbAccesion = line[29:38].strip()
seqadv.dbRes = line[39:42].strip()
seqadv.dbSeq = int(line[43:48])
try:
seqadv.dbSeq = int(line[43:48])
except:
seqadv.dbSeq = None
seqadv.conflict = line[49:70].strip()

counter += 1
Expand Down Expand Up @@ -1092,8 +1095,8 @@ def parse_format33(file):

elif record == 'ANISOU':

record_element = AtomRecord()
model.record.append(record_element)
#record_element = AtomRecord()
#model.record.append(record_element)

if record_element.serial!=int(line[6:11]):
raise ValueError("ANISOU record not referring previous atom record.")
Expand Down
1 change: 1 addition & 0 deletions molsysmt/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def path(package, file):
systems['chicken villin HP35']['chicken_villin_HP35_solvated.h5msm'] = path('molsysmt.data.h5msm', 'chicken_villin_HP35_solvated.h5msm')
systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.dcd'] = path('molsysmt.data.dcd', 'traj_chicken_villin_HP35_solvated.dcd')
systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.h5'] = path('molsysmt.data.h5', 'traj_chicken_villin_HP35_solvated.h5')
systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.h5msm'] = path('molsysmt.data.h5msm', 'traj_chicken_villin_HP35_solvated.h5msm')


# T4 Lysozyme L99A
Expand Down
121 changes: 17 additions & 104 deletions sandbox/Tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ea2e8c1e89bc4d219d42d82c9108c88f",
"model_id": "95de59dde5df459d82c20bbf895a5d69",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -36,158 +36,71 @@
{
"cell_type": "code",
"execution_count": 2,
"id": "e4442462-d13a-4102-831e-53432b0b04de",
"id": "a16f2547-2fb8-4db4-9016-9dec5ea6f43e",
"metadata": {},
"outputs": [],
"source": [
"molsys_1 = msm.convert(systems['alanine dipeptide']['alanine_dipeptide.h5msm'], to_form='molsysmt.MolSys')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "48649be7-9724-48f0-9f73-1c8ad9f577d2",
"metadata": {},
"outputs": [],
"source": [
"molsys_2 = msm.structure.translate(molsys_1, translation='[0.5, 0.0, 0.0] nm')"
"from molsysmt.native import H5MSMFileHandler"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "588d98cf-50f6-4a99-a562-d207ffb7e869",
"id": "dd50ad05-29ea-40f0-9559-e0879608c639",
"metadata": {},
"outputs": [],
"source": [
"molsys_merged = msm.merge([molsys_1, molsys_2], keep_ids=False)"
"molsys = msm.systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.h5msm']"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "038cd459-facb-47d5-ae4f-26deefc4a9e1",
"id": "77f6def6-7552-42fd-ba30-e0bdc269a5f3",
"metadata": {},
"outputs": [],
"source": [
"msm.build.define_new_chain(molsys_merged)"
"handler = H5MSMFileHandler(molsys)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8aa9e648-9c87-4701-bba5-3bf2d5aff9d9",
"execution_count": 25,
"id": "765f4408-8691-4868-9e0f-fbcd00d9b526",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>chain_id</th>\n",
" <th>chain_name</th>\n",
" <th>chain_type</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>A</td>\n",
" <td>system</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" chain_id chain_name chain_type\n",
"0 0 A system"
"4456"
]
},
"execution_count": 6,
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"molsys_merged.topology.chains"
"handler.file['topology']['atoms']['name'].shape[0]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "0d985652-a9f6-4617-b92e-c7fef89f24f6",
"metadata": {},
"outputs": [],
"source": [
"view = msm.view(molsys_merged, viewer='NGLView')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "4eff5af0-50ea-4c4a-a6b9-73c21170159e",
"execution_count": null,
"id": "985a9ddf-8653-4212-8d69-319d9c439840",
"metadata": {},
"outputs": [],
"source": [
"comparison = msm.compare(view, molsys_merged, attribute_type='topological',\n",
" coordinates=True)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ddbf7195-e17f-43b4-a70a-8074f72d7ee5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"comparison"
"pdb_file_handler.entry.crystallographic_and_coordinate_transformation.scale.u2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c305a1e-1f6c-4ecf-8138-0f55ade00df8",
"id": "1d7e2708-12cf-4bfe-8ed4-5f88c37430e7",
"metadata": {},
"outputs": [],
"source": [
" molsys_1 = msm.convert(systems['alanine dipeptide']['alanine_dipeptide.h5msm'], to_form='molsysmt.MolSys')\n",
" molsys_2 = msm.structure.translate(molsys_1, translation='[0.5, 0.0, 0.0] nm')\n",
" molsys_merged = msm.merge([molsys_1, molsys_2], keep_ids=False)\n",
" msm.build.define_new_chain(molsys_merged, selection='all', chain_id=0, chain_name='A')\n",
" view = msm.view(molsys_merged, viewer='NGLView')\n",
" comparison = msm.compare(view, molsys_merged, attribute_type='topological',\n",
" coordinates=True)\n",
" assert comparison\n"
]
"source": []
}
],
"metadata": {
Expand Down
27 changes: 27 additions & 0 deletions tests/native/test_h5msm_file_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
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.native import H5MSMFileHandler
from molsysmt._private.files_and_directories import temp_filename

def test_pdb_file_handler_1():

molsys = msm.systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.h5msm']
handler = H5MSMFileHandler(molsys)
assert 4456==handler.file['topology']['atoms']['name'].shape[0]

def test_pdb_file_handler_2():

topology = msm.convert(msm.systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.h5msm'],
'molsysmt.Topology')
tmpfile = str(temp_filename(extension='h5msm'))
molsys = H5MSMFileHandler(tmpfile, 'w')
molsys.write_topology(topology)
molsys.close()

handler = H5MSMFileHandler(tmpfile)
assert 4456==handler.file['topology']['atoms']['name'].shape[0]

58 changes: 58 additions & 0 deletions tests/native/test_pdb_file_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
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.native import PDBFileHandler

import sys

if sys.version_info[1] in (10,11):
from importlib.resources import files
def path(package, file):
return files(package).joinpath(file)
elif sys.version_info[1] in (8,9):
from pathlib import PurePath
parent = PurePath(__file__).parent
def path(package, file):
data_dir = package.split('.')[-1]
return parent.joinpath('data/'+data_dir+'/'+file).__str__()

systems = {}

systems['3c0f.pdb'] = str(path('molsysmt.data.pdb', '3c0f.pdb'))
systems['1bnf.pdb'] = str(path('molsysmt.data.pdb', '1bnf.pdb'))
systems['3c8h.pdb'] = str(path('molsysmt.data.pdb', '3c8h.pdb'))
systems['2vgy.pdb'] = str(path('molsysmt.data.pdb', '2vgy.pdb'))
systems['5ip4.pdb'] = str(path('molsysmt.data.pdb', '5ip4.pdb'))

def test_pdb_file_handler_1():

pdb_file_handler = PDBFileHandler(systems['3c0f.pdb'])
pdb_file_handler.load()
assert pdb_file_handler.entry.title.source[0].organism_scientific == 'ARCHAEOGLOBUS FULGIDUS DSM 4304'

def test_pdb_file_handler_2():

pdb_file_handler = PDBFileHandler(systems['1bnf.pdb'])
pdb_file_handler.load()
assert pdb_file_handler.entry.connectivity.conect[4].atomSerNum == 1339

def test_pdb_file_handler_3():

pdb_file_handler = PDBFileHandler(systems['3c8h.pdb'])
pdb_file_handler.load()
assert pdb_file_handler.entry.coordinate.model[0].record[0].anisou11 == 9993

def test_pdb_file_handler_4():

pdb_file_handler = PDBFileHandler(systems['2vgy.pdb'])
pdb_file_handler.load()
assert pdb_file_handler.entry.coordinate.model[0].record[0].anisou11 == 10496

def test_pdb_file_handler_5():

pdb_file_handler = PDBFileHandler(systems['5ip4.pdb'])
pdb_file_handler.load()
assert pdb_file_handler.entry.crystallographic_and_coordinate_transformation.scale.u2 == 0.0

0 comments on commit 8121025

Please sign in to comment.