molutils 0.2.0__tar.gz → 0.3.0__tar.gz
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-0.2.0 → molutils-0.3.0}/PKG-INFO +2 -2
- {molutils-0.2.0 → molutils-0.3.0}/molutils/__init__.py +3 -1
- {molutils-0.2.0 → molutils-0.3.0}/molutils/__main__.py +1 -1
- {molutils-0.2.0 → molutils-0.3.0}/molutils/_core/count.py +19 -1
- molutils-0.3.0/molutils/_core/extract.py +94 -0
- molutils-0.3.0/molutils/_core/list_.py +53 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils/_parsers/parser_pdb.py +8 -0
- molutils-0.3.0/molutils/_ui/app_main.py +45 -0
- molutils-0.3.0/molutils/_ui/app_subcommand.py +23 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils/_ui/fy_help.fyh +4 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils/_ui/fy_rules.fyr +3 -0
- molutils-0.3.0/molutils/_version.py +1 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils.egg-info/PKG-INFO +2 -2
- {molutils-0.2.0 → molutils-0.3.0}/molutils.egg-info/SOURCES.txt +2 -1
- molutils-0.3.0/molutils.egg-info/requires.txt +1 -0
- {molutils-0.2.0 → molutils-0.3.0}/setup.py +1 -1
- molutils-0.2.0/molutils/_core/extract.py +0 -44
- molutils-0.2.0/molutils/_core/list_.py +0 -16
- molutils-0.2.0/molutils/_ui/app.py +0 -123
- molutils-0.2.0/molutils/_version.py +0 -1
- molutils-0.2.0/molutils.egg-info/requires.txt +0 -1
- {molutils-0.2.0 → molutils-0.3.0}/LICENSE.md +0 -0
- {molutils-0.2.0 → molutils-0.3.0}/README.md +0 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils/_core/__init__.py +0 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils/_parsers/__init__.py +0 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils/_ui/__init__.py +0 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils.egg-info/dependency_links.txt +0 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils.egg-info/entry_points.txt +0 -0
- {molutils-0.2.0 → molutils-0.3.0}/molutils.egg-info/top_level.txt +0 -0
- {molutils-0.2.0 → molutils-0.3.0}/pyproject.toml +0 -0
- {molutils-0.2.0 → molutils-0.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: molutils
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Collection of tools for preprocessing or summarizing details from biomolecular structure files.
|
|
5
5
|
Home-page: https://github.com/diegobarmor/molutils
|
|
6
6
|
Author: DiegoBarMor
|
|
@@ -12,7 +12,7 @@ Classifier: Operating System :: OS Independent
|
|
|
12
12
|
Requires-Python: >=3.10
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE.md
|
|
15
|
-
Requires-Dist: freyacli==0.3.
|
|
15
|
+
Requires-Dist: freyacli==0.3.2
|
|
16
16
|
Dynamic: author
|
|
17
17
|
Dynamic: author-email
|
|
18
18
|
Dynamic: classifier
|
|
@@ -2,8 +2,10 @@ from ._version import __version__
|
|
|
2
2
|
|
|
3
3
|
from ._parsers.parser_pdb import ParserPDB
|
|
4
4
|
|
|
5
|
+
from ._ui.app_subcommand import AppSubcommand
|
|
6
|
+
|
|
5
7
|
from ._core.list_ import List
|
|
6
8
|
from ._core.count import Count
|
|
7
9
|
from ._core.extract import Extract
|
|
8
10
|
|
|
9
|
-
from ._ui.
|
|
11
|
+
from ._ui.app_main import AppMain
|
|
@@ -9,7 +9,7 @@ except ImportError:
|
|
|
9
9
|
|
|
10
10
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
11
11
|
def main():
|
|
12
|
-
mu.
|
|
12
|
+
mu.AppMain(sys.argv).run()
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
################################################################################
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
|
|
3
|
+
import molutils as mu
|
|
4
|
+
|
|
3
5
|
# //////////////////////////////////////////////////////////////////////////////
|
|
4
|
-
class Count:
|
|
6
|
+
class Count(mu.AppSubcommand):
|
|
7
|
+
# -------------------------------------------------------------------------- UI SECTION
|
|
8
|
+
def run(self):
|
|
9
|
+
command = self.main.subcommands.pop(0)
|
|
10
|
+
|
|
11
|
+
if command == "models": return self.app_count_models()
|
|
12
|
+
|
|
13
|
+
raise ValueError(f"Unknown command: {command}")
|
|
14
|
+
|
|
15
|
+
|
|
5
16
|
# --------------------------------------------------------------------------
|
|
17
|
+
def app_count_models(self):
|
|
18
|
+
path_in = self.main.get_arg_path("path_in")
|
|
19
|
+
self.main.assert_file_in(path_in)
|
|
20
|
+
print(mu.Count.models(path_in))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# -------------------------------------------------------------------------- LOGIC SECTION
|
|
6
24
|
@classmethod
|
|
7
25
|
def models(cls, path_pdb: Path) -> int:
|
|
8
26
|
data = path_pdb.read_text()
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from collections import defaultdict
|
|
2
|
+
|
|
3
|
+
import molutils as mu
|
|
4
|
+
|
|
5
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
6
|
+
class Extract(mu.AppSubcommand):
|
|
7
|
+
# -------------------------------------------------------------------------- UI SECTION
|
|
8
|
+
def run(self):
|
|
9
|
+
command = self.subcommands.pop(0)
|
|
10
|
+
|
|
11
|
+
if command == "models": return self.app_extract_models()
|
|
12
|
+
if command == "chains": return self.app_extract_chains()
|
|
13
|
+
|
|
14
|
+
raise ValueError(f"Unknown command: {command}")
|
|
15
|
+
|
|
16
|
+
# --------------------------------------------------------------------------
|
|
17
|
+
def app_extract_models(self):
|
|
18
|
+
path_in = self.main.get_arg_path("path_in")
|
|
19
|
+
self.main.assert_file_in(path_in)
|
|
20
|
+
|
|
21
|
+
folder_out = self.main.get_arg_path("folder_out", default = path_in.parent)
|
|
22
|
+
self.main.assert_dir_out(folder_out)
|
|
23
|
+
|
|
24
|
+
data_pdb = path_in.read_text()
|
|
25
|
+
|
|
26
|
+
if self.main.get_arg_bool("first_only"):
|
|
27
|
+
_, model = mu.Extract.next_model(data_pdb)
|
|
28
|
+
path_out = folder_out / f"{path_in.stem}.m0.pdb"
|
|
29
|
+
path_out.write_text(model)
|
|
30
|
+
return
|
|
31
|
+
|
|
32
|
+
for i, model in enumerate(mu.Extract.iter_models(data_pdb)):
|
|
33
|
+
path_out = folder_out / f"{path_in.stem}.m{i:03}.pdb"
|
|
34
|
+
path_out.write_text(model)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# --------------------------------------------------------------------------
|
|
38
|
+
def app_extract_chains(self):
|
|
39
|
+
path_in = self.main.get_arg_path("path_in")
|
|
40
|
+
self.main.assert_file_in(path_in)
|
|
41
|
+
|
|
42
|
+
folder_out = self.main.get_arg_path("folder_out", default = path_in.parent)
|
|
43
|
+
self.main.assert_dir_out(folder_out)
|
|
44
|
+
|
|
45
|
+
data_pdb = path_in.read_text()
|
|
46
|
+
|
|
47
|
+
chains = mu.Extract.split_chains(data_pdb)
|
|
48
|
+
|
|
49
|
+
chain_ids = mu.List.chains(path_in, first_only = True) \
|
|
50
|
+
if self.main.get_arg_bool("first_only") else chains.keys()
|
|
51
|
+
|
|
52
|
+
for chain_id in chain_ids:
|
|
53
|
+
path_out = folder_out / f"{path_in.stem}.{chain_id}.pdb"
|
|
54
|
+
path_out.write_text(chains[chain_id])
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# -------------------------------------------------------------------------- LOGIC SECTION
|
|
58
|
+
@classmethod
|
|
59
|
+
def next_model(cls, data: str, start: int = 0) -> tuple[int, str]:
|
|
60
|
+
idx_0 = data.find("\nMODEL", start)
|
|
61
|
+
if idx_0 == -1: return -1, data
|
|
62
|
+
|
|
63
|
+
idx_1 = data.find("\nENDMDL", idx_0)
|
|
64
|
+
if idx_1 == -1: return -1, data[idx_0:]
|
|
65
|
+
|
|
66
|
+
idx_1 += len("\nENDMDL")
|
|
67
|
+
return idx_1, data[idx_0:idx_1] + "\nEND"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# --------------------------------------------------------------------------
|
|
71
|
+
@classmethod
|
|
72
|
+
def iter_models(cls, data: str):
|
|
73
|
+
while data:
|
|
74
|
+
idx, model = cls.next_model(data)
|
|
75
|
+
yield model
|
|
76
|
+
if idx == -1: break
|
|
77
|
+
data = data[idx:]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# --------------------------------------------------------------------------
|
|
81
|
+
@classmethod
|
|
82
|
+
def split_chains(cls, data: str) -> dict[str, str]:
|
|
83
|
+
pdb = mu.ParserPDB(data)
|
|
84
|
+
chains = defaultdict(list)
|
|
85
|
+
for line in pdb.iter_atoms():
|
|
86
|
+
chain_id = mu.ParserPDB.get_chainid(line)
|
|
87
|
+
chains[chain_id].append(line)
|
|
88
|
+
return {
|
|
89
|
+
chain_id: mu.ParserPDB.join_lines(lines)
|
|
90
|
+
for chain_id, lines in chains.items()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import molutils as mu
|
|
4
|
+
|
|
5
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
6
|
+
class List(mu.AppSubcommand):
|
|
7
|
+
# -------------------------------------------------------------------------- UI SECTION
|
|
8
|
+
def run(self):
|
|
9
|
+
command = self.main.subcommands.pop(0)
|
|
10
|
+
|
|
11
|
+
if command == "chains": return self.app_list_chains()
|
|
12
|
+
if command == "resids": return self.app_list_resids()
|
|
13
|
+
|
|
14
|
+
raise ValueError(f"Unknown command: {command}")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# --------------------------------------------------------------------------
|
|
18
|
+
def app_list_chains(self):
|
|
19
|
+
path_in = self.main.get_arg_path("path_in")
|
|
20
|
+
first_only = self.main.get_arg_bool("first_only")
|
|
21
|
+
self.main.assert_file_in(path_in)
|
|
22
|
+
print(*mu.List.chains(path_in, first_only))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# --------------------------------------------------------------------------
|
|
26
|
+
def app_list_resids(self):
|
|
27
|
+
path_in = self.main.get_arg_path("path_in")
|
|
28
|
+
self.main.assert_file_in(path_in)
|
|
29
|
+
print(*mu.List.resids(path_in))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# -------------------------------------------------------------------------- LOGIC SECTION
|
|
33
|
+
@classmethod
|
|
34
|
+
def chains(cls, path_pdb: Path, first_only: bool = False) -> list[str]:
|
|
35
|
+
pdb = mu.ParserPDB.from_file(path_pdb)
|
|
36
|
+
gen_chain_ids = (mu.ParserPDB.get_chainid(line) for line in pdb.iter_atoms())
|
|
37
|
+
if first_only: return mu.ParserPDB.safe_next(gen_chain_ids)
|
|
38
|
+
return sorted(set(gen_chain_ids))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# --------------------------------------------------------------------------
|
|
42
|
+
@classmethod
|
|
43
|
+
def resids(cls, path_pdb: Path) -> list[str]:
|
|
44
|
+
"""Returns list of unique residue identifiers in the format "chainid.resid"."""
|
|
45
|
+
pdb = mu.ParserPDB.from_file(path_pdb)
|
|
46
|
+
gen_resids = (
|
|
47
|
+
f"{mu.ParserPDB.get_chainid(line)}.{mu.ParserPDB.get_resid(line)}"
|
|
48
|
+
for line in pdb.iter_atoms()
|
|
49
|
+
)
|
|
50
|
+
return sorted(set(gen_resids))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -4,6 +4,8 @@ from pathlib import Path
|
|
|
4
4
|
class ParserPDB:
|
|
5
5
|
LENGTH_RECORD = 80
|
|
6
6
|
IDX_CHAIN_ID = 21
|
|
7
|
+
IDX0_RESID = 22
|
|
8
|
+
IDX1_RESID = 26
|
|
7
9
|
|
|
8
10
|
# --------------------------------------------------------------------------
|
|
9
11
|
def __init__(self, data_pdb: str):
|
|
@@ -44,4 +46,10 @@ class ParserPDB:
|
|
|
44
46
|
except IndexError: raise ValueError(f"Unexpected format of ATOM records in PDB file")
|
|
45
47
|
|
|
46
48
|
|
|
49
|
+
# --------------------------------------------------------------------------
|
|
50
|
+
@classmethod
|
|
51
|
+
def get_resid(cls, line: str) -> str:
|
|
52
|
+
return line[cls.IDX0_RESID:cls.IDX1_RESID].strip()
|
|
53
|
+
|
|
54
|
+
|
|
47
55
|
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import molutils as mu
|
|
4
|
+
|
|
5
|
+
import freyacli as fy
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
9
|
+
class AppMain(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 == "list" : return mu.List(self).run()
|
|
28
|
+
if command == "count" : return mu.Count(self).run()
|
|
29
|
+
if command == "extract": return mu.Extract(self).run()
|
|
30
|
+
if command == "select" : return self._run_select()
|
|
31
|
+
raise ValueError(f"Unknown command: {command}")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# --------------------------------------------------------------------------
|
|
35
|
+
def _run_select(self):
|
|
36
|
+
query = self.get_arg_str("query")
|
|
37
|
+
path_in = self.get_arg_path("path_in")
|
|
38
|
+
path_out = self.get_arg_path("path_out")
|
|
39
|
+
self.assert_file_in(path_in)
|
|
40
|
+
|
|
41
|
+
import MDAnalysis as mda
|
|
42
|
+
mda.Universe(path_in).select_atoms(query).write(path_out)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
import molutils as mu
|
|
4
|
+
|
|
5
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
6
|
+
class AppSubcommand(ABC):
|
|
7
|
+
"""
|
|
8
|
+
Base class for all subcommands of the molutils suite of applications.
|
|
9
|
+
They hold a reference to the unique `AppMain` instance, which they can use to access the CLI arguments.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# --------------------------------------------------------------------------
|
|
13
|
+
def __init__(self, app_main: "mu.AppMain"):
|
|
14
|
+
self.main = app_main
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# --------------------------------------------------------------------------
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def run(self):
|
|
20
|
+
raise NotImplementedError()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
!fyh:path_in Path of a PDB file.
|
|
8
8
|
!fyh:first_only Use this flag for displaying only the first chain of the structure.
|
|
9
9
|
!@
|
|
10
|
+
@resids
|
|
11
|
+
!fyh:_ Lists the residue identifiers in a PDB file in the format "chainid.resid".
|
|
12
|
+
!fyh:path_in Path of a PDB file.
|
|
13
|
+
!@
|
|
10
14
|
!@
|
|
11
15
|
|
|
12
16
|
@count
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: molutils
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Collection of tools for preprocessing or summarizing details from biomolecular structure files.
|
|
5
5
|
Home-page: https://github.com/diegobarmor/molutils
|
|
6
6
|
Author: DiegoBarMor
|
|
@@ -12,7 +12,7 @@ Classifier: Operating System :: OS Independent
|
|
|
12
12
|
Requires-Python: >=3.10
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE.md
|
|
15
|
-
Requires-Dist: freyacli==0.3.
|
|
15
|
+
Requires-Dist: freyacli==0.3.2
|
|
16
16
|
Dynamic: author
|
|
17
17
|
Dynamic: author-email
|
|
18
18
|
Dynamic: classifier
|
|
@@ -18,6 +18,7 @@ molutils/_core/list_.py
|
|
|
18
18
|
molutils/_parsers/__init__.py
|
|
19
19
|
molutils/_parsers/parser_pdb.py
|
|
20
20
|
molutils/_ui/__init__.py
|
|
21
|
-
molutils/_ui/
|
|
21
|
+
molutils/_ui/app_main.py
|
|
22
|
+
molutils/_ui/app_subcommand.py
|
|
22
23
|
molutils/_ui/fy_help.fyh
|
|
23
24
|
molutils/_ui/fy_rules.fyr
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
freyacli==0.3.2
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
from collections import defaultdict
|
|
2
|
-
|
|
3
|
-
import molutils as mu
|
|
4
|
-
|
|
5
|
-
# //////////////////////////////////////////////////////////////////////////////
|
|
6
|
-
class Extract:
|
|
7
|
-
# --------------------------------------------------------------------------
|
|
8
|
-
@classmethod
|
|
9
|
-
def next_model(cls, data: str, start: int = 0) -> tuple[int, str]:
|
|
10
|
-
idx_0 = data.find("\nMODEL", start)
|
|
11
|
-
if idx_0 == -1: return -1, data
|
|
12
|
-
|
|
13
|
-
idx_1 = data.find("\nENDMDL", idx_0)
|
|
14
|
-
if idx_1 == -1: return -1, data[idx_0:]
|
|
15
|
-
|
|
16
|
-
idx_1 += len("\nENDMDL")
|
|
17
|
-
return idx_1, data[idx_0:idx_1] + "\nEND"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# --------------------------------------------------------------------------
|
|
21
|
-
@classmethod
|
|
22
|
-
def iter_models(cls, data: str):
|
|
23
|
-
while data:
|
|
24
|
-
idx, model = cls.next_model(data)
|
|
25
|
-
yield model
|
|
26
|
-
if idx == -1: break
|
|
27
|
-
data = data[idx:]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# --------------------------------------------------------------------------
|
|
31
|
-
@classmethod
|
|
32
|
-
def split_chains(cls, data: str) -> dict[str, str]:
|
|
33
|
-
pdb = mu.ParserPDB(data)
|
|
34
|
-
chains = defaultdict(list)
|
|
35
|
-
for line in pdb.iter_atoms():
|
|
36
|
-
chain_id = mu.ParserPDB.get_chainid(line)
|
|
37
|
-
chains[chain_id].append(line)
|
|
38
|
-
return {
|
|
39
|
-
chain_id: mu.ParserPDB.join_lines(lines)
|
|
40
|
-
for chain_id, lines in chains.items()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
|
|
3
|
-
import molutils as mu
|
|
4
|
-
|
|
5
|
-
# //////////////////////////////////////////////////////////////////////////////
|
|
6
|
-
class List:
|
|
7
|
-
# --------------------------------------------------------------------------
|
|
8
|
-
@classmethod
|
|
9
|
-
def chains(cls, path_pdb: Path, first_only: bool = False) -> list[str]:
|
|
10
|
-
pdb = mu.ParserPDB.from_file(path_pdb)
|
|
11
|
-
gen_chain_ids = (mu.ParserPDB.get_chainid(line) for line in pdb.iter_atoms())
|
|
12
|
-
if first_only: return mu.ParserPDB.safe_next(gen_chain_ids)
|
|
13
|
-
return sorted(set(gen_chain_ids))
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -1,123 +0,0 @@
|
|
|
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 == "list" : return self._run_list()
|
|
28
|
-
if command == "count" : return self._run_count()
|
|
29
|
-
if command == "extract": return self._run_extract()
|
|
30
|
-
if command == "select" : return self._run_select()
|
|
31
|
-
raise ValueError(f"Unknown command: {command}")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# --------------------------------------------------------------------------
|
|
35
|
-
def _run_list(self):
|
|
36
|
-
def list_chains():
|
|
37
|
-
path_in = self.get_arg_path("path_in")
|
|
38
|
-
first_only = self.get_arg_bool("first_only")
|
|
39
|
-
self.assert_file_in(path_in)
|
|
40
|
-
print(*mu.List.chains(path_in, first_only))
|
|
41
|
-
|
|
42
|
-
command = self.subcommands.pop(0)
|
|
43
|
-
|
|
44
|
-
if command == "chains": return list_chains()
|
|
45
|
-
|
|
46
|
-
raise ValueError(f"Unknown command: {command}")
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# --------------------------------------------------------------------------
|
|
50
|
-
def _run_count(self):
|
|
51
|
-
def count_models():
|
|
52
|
-
path_in = self.get_arg_path("path_in")
|
|
53
|
-
self.assert_file_in(path_in)
|
|
54
|
-
print(mu.Count.models(path_in))
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
command = self.subcommands.pop(0)
|
|
58
|
-
|
|
59
|
-
if command == "models": return count_models()
|
|
60
|
-
|
|
61
|
-
raise ValueError(f"Unknown command: {command}")
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
# --------------------------------------------------------------------------
|
|
65
|
-
def _run_extract(self):
|
|
66
|
-
def extract_models():
|
|
67
|
-
path_in = self.get_arg_path("path_in")
|
|
68
|
-
self.assert_file_in(path_in)
|
|
69
|
-
|
|
70
|
-
folder_out = self.get_arg_path("folder_out", default = path_in.parent)
|
|
71
|
-
self.assert_dir_out(folder_out)
|
|
72
|
-
|
|
73
|
-
data_pdb = path_in.read_text()
|
|
74
|
-
|
|
75
|
-
if self.get_arg_bool("first_only"):
|
|
76
|
-
_, model = mu.Extract.next_model(data_pdb)
|
|
77
|
-
path_out = folder_out / f"{path_in.stem}.m0.pdb"
|
|
78
|
-
path_out.write_text(model)
|
|
79
|
-
return
|
|
80
|
-
|
|
81
|
-
for i, model in enumerate(mu.Extract.iter_models(data_pdb)):
|
|
82
|
-
path_out = folder_out / f"{path_in.stem}.m{i:03}.pdb"
|
|
83
|
-
path_out.write_text(model)
|
|
84
|
-
|
|
85
|
-
def extract_chains():
|
|
86
|
-
path_in = self.get_arg_path("path_in")
|
|
87
|
-
self.assert_file_in(path_in)
|
|
88
|
-
|
|
89
|
-
folder_out = self.get_arg_path("folder_out", default = path_in.parent)
|
|
90
|
-
self.assert_dir_out(folder_out)
|
|
91
|
-
|
|
92
|
-
data_pdb = path_in.read_text()
|
|
93
|
-
|
|
94
|
-
chains = mu.Extract.split_chains(data_pdb)
|
|
95
|
-
|
|
96
|
-
chain_ids = mu.List.chains(path_in, first_only = True) \
|
|
97
|
-
if self.get_arg_bool("first_only") else chains.keys()
|
|
98
|
-
|
|
99
|
-
for chain_id in chain_ids:
|
|
100
|
-
path_out = folder_out / f"{path_in.stem}.{chain_id}.pdb"
|
|
101
|
-
path_out.write_text(chains[chain_id])
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
command = self.subcommands.pop(0)
|
|
105
|
-
|
|
106
|
-
if command == "models": return extract_models()
|
|
107
|
-
if command == "chains": return extract_chains()
|
|
108
|
-
|
|
109
|
-
raise ValueError(f"Unknown command: {command}")
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
# --------------------------------------------------------------------------
|
|
113
|
-
def _run_select(self):
|
|
114
|
-
query = self.get_arg_str("query")
|
|
115
|
-
path_in = self.get_arg_path("path_in")
|
|
116
|
-
path_out = self.get_arg_path("path_out")
|
|
117
|
-
self.assert_file_in(path_in)
|
|
118
|
-
|
|
119
|
-
import MDAnalysis as mda
|
|
120
|
-
mda.Universe(path_in).select_atoms(query).write(path_out)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
# //////////////////////////////////////////////////////////////////////////////
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
freyacli==0.3.1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|