From 25e7a2aa675a4d65071723c70b9b4cc56a070b8e Mon Sep 17 00:00:00 2001 From: Pegerto Date: Tue, 24 Sep 2024 23:23:47 +0100 Subject: [PATCH] fix required resname (#26) --- CHANGELOG.md | 2 + mdakit_sasa/analysis/sasaanalysis.py | 8 +++- .../tests/analysis/test_sasaanalysis.py | 9 ++-- mdakit_sasa/tests/data/image_vf.data | 48 +++++++++++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 mdakit_sasa/tests/data/image_vf.data diff --git a/CHANGELOG.md b/CHANGELOG.md index c7069b2..60cef09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ The rules for this file: * YYYY-MM-DD date format (following ISO 8601) * accompany each entry with github issue/PR number (Issue #xyz) --> +## 0.2.7 + * [Fix] Acess resname safely and test agains DCD ## 0.2.0 * [New] Include segmentid for freesasa calculation. diff --git a/mdakit_sasa/analysis/sasaanalysis.py b/mdakit_sasa/analysis/sasaanalysis.py index a45de3f..a06a514 100644 --- a/mdakit_sasa/analysis/sasaanalysis.py +++ b/mdakit_sasa/analysis/sasaanalysis.py @@ -11,6 +11,7 @@ from typing import Union, TYPE_CHECKING from MDAnalysis.analysis.base import AnalysisBase +from MDAnalysis.exceptions import NoDataError import numpy as np import freesasa import os @@ -90,7 +91,12 @@ def _single_frame(self): # FreeSasa structure accepts PDBS if not available requires to reconstruct the structure using `addAtom` for a in self.atomgroup: x,y,z = a.position - structure.addAtom(a.type.rjust(2), a.resname, a.resnum.item(), a.segid, x, y, z) + try: + resname = a.resname + except NoDataError: + resname = 'ANY' # Default classifier value + + structure.addAtom(a.type.rjust(2), resname, a.resnum.item(), a.segid, x, y, z) # Define 1 cpu for windows avoid freesasa code to calculate it. parametes = freesasa.Parameters() diff --git a/mdakit_sasa/tests/analysis/test_sasaanalysis.py b/mdakit_sasa/tests/analysis/test_sasaanalysis.py index 9728729..1efc616 100644 --- a/mdakit_sasa/tests/analysis/test_sasaanalysis.py +++ b/mdakit_sasa/tests/analysis/test_sasaanalysis.py @@ -75,13 +75,14 @@ def test_residue_sasa_calculation_results(self, analysis): assert analysis.results['residue_area'].shape == (3,25) @pytest.mark.parametrize( - "pdb_file_name, res_numbers", + "filename, res_numbers", [ - ('134L.pdb', 201) + ('134L.pdb', 201), + ('image_vf.data', 1) ] ) - def test(self, pdb_file_name, res_numbers): - u = mda.Universe(PARENT / 'data' / pdb_file_name) + def test(self, filename, res_numbers): + u = mda.Universe(PARENT / 'data' / filename) analysis = SASAAnalysis(u) analysis.run() assert(len(analysis.results.residue_area[0]) == res_numbers) diff --git a/mdakit_sasa/tests/data/image_vf.data b/mdakit_sasa/tests/data/image_vf.data new file mode 100644 index 0000000..e1dc19f --- /dev/null +++ b/mdakit_sasa/tests/data/image_vf.data @@ -0,0 +1,48 @@ +LAMMPS data file via write_data, version 30 Jul 2021, timestep = 0 + +7 atoms +2 atom types +1 bonds +1 bond types + +0 10 xlo xhi +0 10 ylo yhi +0 10 zlo zhi + +Masses + +1 1 +2 1 + +Pair Coeffs # lj/cut + +1 1 1 +2 1 1 + +Bond Coeffs # harmonic + +1 1000 1 + +Atoms # full + +4 0 2 0 5.891131260960588 3.398519062578611 0.23689615365476138 0 0 0 +1 0 1 0 4.999443228802319 5.0001459354508775 5.5008776144874 0 0 0 +2 0 1 0 5.000001730605194 4.999999546244266 4.500875455656523 0 0 0 +6 0 2 0 8.27919675422795 8.459848309149896 4.670531882285388 0 0 0 +3 0 2 0 3.362012829847722 5.522388563244657 8.669485965475673 0 0 0 +5 0 2 0 6.586761886625301 3.97905466100164 9.576146361865367 0 0 0 +7 0 2 0 7.621069760835089 6.390558075605001 9.73656065860773 0 0 0 + +Velocities + +4 -0.07044405565641114 0.22797649438575432 0.9964537327696037 +1 1.6773916431557685 0.920692478778414 -2.57312540408295 +2 0.6247600152168848 1.0635940922731792 -0.09111771815842719 +6 0.28742689473258004 -0.5462919186206593 -1.8993269764408356 +3 -0.9529069979679257 -0.9763723022827592 3.1367559503110862 +5 -0.7649018752874791 -2.004540572487937 0.652141765065628 +7 -0.8013256241934161 1.3149417279540099 -0.22178134946410677 + +Bonds + +1 1 1 2 \ No newline at end of file