molutils 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- molutils/__init__.py +6 -0
- molutils/__main__.py +20 -0
- molutils/_core/__init__.py +0 -0
- molutils/_core/count.py +20 -0
- molutils/_core/extract.py +28 -0
- molutils/_ui/__init__.py +0 -0
- molutils/_ui/app.py +76 -0
- molutils/_ui/fy_help.fyh +20 -0
- molutils/_ui/fy_rules.fyr +12 -0
- molutils/_version.py +1 -0
- molutils-0.1.0.dist-info/METADATA +27 -0
- molutils-0.1.0.dist-info/RECORD +16 -0
- molutils-0.1.0.dist-info/WHEEL +5 -0
- molutils-0.1.0.dist-info/entry_points.txt +2 -0
- molutils-0.1.0.dist-info/licenses/LICENSE.md +22 -0
- molutils-0.1.0.dist-info/top_level.txt +1 -0
molutils/__init__.py
ADDED
molutils/__main__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
import molutils as mu
|
|
6
|
+
except ImportError:
|
|
7
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
8
|
+
import molutils as mu
|
|
9
|
+
|
|
10
|
+
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
11
|
+
def main():
|
|
12
|
+
mu.App(sys.argv).run()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
################################################################################
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
main()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
################################################################################
|
|
File without changes
|
molutils/_core/count.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
4
|
+
class Count:
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
@classmethod
|
|
7
|
+
def models(cls, path_pdb: Path) -> int:
|
|
8
|
+
data = path_pdb.read_text()
|
|
9
|
+
return max(1, cls._count_substring('\n'+data, "\nMODEL"))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# --------------------------------------------------------------------------
|
|
13
|
+
@staticmethod
|
|
14
|
+
def _count_substring(string: str, substring: str) -> int:
|
|
15
|
+
"""Counts the number of occurrences of `substring` in `string`."""
|
|
16
|
+
replaced = string.replace(substring, "")
|
|
17
|
+
return (len(string) - len(replaced)) // len(substring)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
4
|
+
class Extract:
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
@classmethod
|
|
7
|
+
def next_model(cls, data: str, start: int = 0) -> tuple[int, str]:
|
|
8
|
+
idx_0 = data.find("\nMODEL", start)
|
|
9
|
+
if idx_0 == -1: return -1, data
|
|
10
|
+
|
|
11
|
+
idx_1 = data.find("\nENDMDL", idx_0)
|
|
12
|
+
if idx_1 == -1: return -1, data[idx_0:]
|
|
13
|
+
|
|
14
|
+
idx_1 += len("\nENDMDL")
|
|
15
|
+
return idx_1, data[idx_0:idx_1] + "\nEND"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# --------------------------------------------------------------------------
|
|
19
|
+
@classmethod
|
|
20
|
+
def iter_models(cls, data: str):
|
|
21
|
+
while data:
|
|
22
|
+
idx, model = cls.next_model(data)
|
|
23
|
+
yield model
|
|
24
|
+
if idx == -1: break
|
|
25
|
+
data = data[idx:]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# //////////////////////////////////////////////////////////////////////////////
|
molutils/_ui/__init__.py
ADDED
|
File without changes
|
molutils/_ui/app.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import molutils as mu
|
|
4
|
+
|
|
5
|
+
import freyacli as fy
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
9
|
+
class App(fy.App):
|
|
10
|
+
_APP_NAME = "molutils"
|
|
11
|
+
_VERSION = mu.__version__
|
|
12
|
+
|
|
13
|
+
# --------------------------------------------------------------------------
|
|
14
|
+
def __init__(self, argv: list[str]):
|
|
15
|
+
dir_ui = Path(__file__).parent
|
|
16
|
+
super().__init__(
|
|
17
|
+
args = argv,
|
|
18
|
+
path_fyr = dir_ui / "fy_rules.fyr",
|
|
19
|
+
path_fyh = dir_ui / "fy_help.fyh",
|
|
20
|
+
)
|
|
21
|
+
self.subcommands = self.get_path_to_root()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# --------------------------------------------------------------------------
|
|
25
|
+
def run(self):
|
|
26
|
+
command = self.subcommands.pop(0)
|
|
27
|
+
if command == "count": return self._run_count()
|
|
28
|
+
if command == "extract": return self._run_extract()
|
|
29
|
+
raise ValueError(f"Unknown command: {command}")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# --------------------------------------------------------------------------
|
|
33
|
+
def _run_count(self):
|
|
34
|
+
def count_models():
|
|
35
|
+
path_pdb = self.get_arg_path("path_pdb")
|
|
36
|
+
self.assert_file_in(path_pdb)
|
|
37
|
+
print(mu.Count.models(path_pdb))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
command = self.subcommands.pop(0)
|
|
41
|
+
|
|
42
|
+
if command == "models": return count_models()
|
|
43
|
+
|
|
44
|
+
raise ValueError(f"Unknown command: {command}")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# --------------------------------------------------------------------------
|
|
48
|
+
def _run_extract(self):
|
|
49
|
+
def extract_models():
|
|
50
|
+
path_pdb = self.get_arg_path("path_pdb")
|
|
51
|
+
self.assert_file_in(path_pdb)
|
|
52
|
+
|
|
53
|
+
folder_out = self.get_arg_path("folder_out", default = path_pdb.parent)
|
|
54
|
+
self.assert_dir_out(folder_out)
|
|
55
|
+
|
|
56
|
+
data_pdb = path_pdb.read_text()
|
|
57
|
+
|
|
58
|
+
if self.get_arg_bool("first_only"):
|
|
59
|
+
_, model = mu.Extract.next_model(data_pdb)
|
|
60
|
+
path_out = folder_out / f"{path_pdb.stem}.m0.pdb"
|
|
61
|
+
path_out.write_text(model)
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
for i, model in enumerate(mu.Extract.iter_models(data_pdb)):
|
|
65
|
+
path_out = folder_out / f"{path_pdb.stem}.m{i:03}.pdb"
|
|
66
|
+
path_out.write_text(model)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
command = self.subcommands.pop(0)
|
|
70
|
+
|
|
71
|
+
if command == "models": return extract_models()
|
|
72
|
+
|
|
73
|
+
raise ValueError(f"Unknown command: {command}")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# //////////////////////////////////////////////////////////////////////////////
|
molutils/_ui/fy_help.fyh
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
!fyh:_ molutils is a collection of tools for preprocessing or summarizing details from biomolecular structure files.
|
|
2
|
+
|
|
3
|
+
@count
|
|
4
|
+
!fyh:_ Provides counts for different aspects of biomolecular structures.
|
|
5
|
+
@models
|
|
6
|
+
!fyh:_ Counts the number of models in a PDB file.
|
|
7
|
+
!fyh:path_pdb Path of a PDB file.
|
|
8
|
+
!@
|
|
9
|
+
!@
|
|
10
|
+
|
|
11
|
+
@extract
|
|
12
|
+
!fyh:_ Extract specific sections of data from biomolecular structures.
|
|
13
|
+
@models
|
|
14
|
+
!fyh:_ Extracts the models in a PDB file into separate files.
|
|
15
|
+
!fyh:path_pdb Path of a PDB file.
|
|
16
|
+
!fyh:folder_out Path of the directory where to place the unpacked models.
|
|
17
|
+
If not provided, the parent directory of the input PDB file will be used.
|
|
18
|
+
!fyh:first_only Use this flag for extracting only the first model of the structure and disregard the rest.
|
|
19
|
+
!@
|
|
20
|
+
!@
|
molutils/_version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: molutils
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Home-page: https://github.com/diegobarmor/molutils
|
|
5
|
+
Author: DiegoBarMor
|
|
6
|
+
Author-email: diegobarmor42@gmail.com
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE.md
|
|
14
|
+
Requires-Dist: freyacli==0.2.0
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: author-email
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: keywords
|
|
22
|
+
Dynamic: license
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
|
|
27
|
+
# molutils
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
molutils/__init__.py,sha256=doAOx0MQnDcbk43OcDM4aLevNgtGXymwuDdEPkR1LRQ,127
|
|
2
|
+
molutils/__main__.py,sha256=G9eOFjly21VHPOrsIsSxoqABwgYFhktdJgMtHNx92Rw,507
|
|
3
|
+
molutils/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
4
|
+
molutils/_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
molutils/_core/count.py,sha256=ER4RbsnttBhuO0goZyl9SHZZX1mXW_Hl5DNugpIU8SY,797
|
|
6
|
+
molutils/_core/extract.py,sha256=RDUT40L3a8bGcb68HnUaaf2G110MiW_wLHAYYFiWLmk,925
|
|
7
|
+
molutils/_ui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
molutils/_ui/app.py,sha256=f1SmIZ4-EZLwU4yy34T1_Zv-kIIYFgKK7cKuudGPxKU,2428
|
|
9
|
+
molutils/_ui/fy_help.fyh,sha256=XVzWK2D2zeNz3_k3ZV4LFD4F-0edZc5LMSAFE8F3wVk,826
|
|
10
|
+
molutils/_ui/fy_rules.fyr,sha256=SVx23E81w_X6leiK9ccZfWWLdHzatg3_XLXgcs2vrXQ,172
|
|
11
|
+
molutils-0.1.0.dist-info/licenses/LICENSE.md,sha256=G3Npy1II_l8uI3esXkymjGGJ3NMlgnk0AwXAQ-YZOb4,1089
|
|
12
|
+
molutils-0.1.0.dist-info/METADATA,sha256=3I2NxeKTmuLbbu2nUUiXOrjceyRlnatTNintEvi-xOY,689
|
|
13
|
+
molutils-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
14
|
+
molutils-0.1.0.dist-info/entry_points.txt,sha256=TRulPkBqBYcqq8wSJs9nUmMDFD6vGTqxfbpOQDjJGqo,52
|
|
15
|
+
molutils-0.1.0.dist-info/top_level.txt,sha256=f6zK2-Ds37TjE0Zuw6AQu_kHLVR_c7JEUIUQaNwQY7Q,9
|
|
16
|
+
molutils-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 Diego Barquero Morera
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
molutils
|