molutils 0.1.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.
Files changed (34) hide show
  1. {molutils-0.1.0 → molutils-0.3.0}/PKG-INFO +6 -3
  2. molutils-0.3.0/README.md +2 -0
  3. molutils-0.3.0/molutils/__init__.py +11 -0
  4. {molutils-0.1.0 → molutils-0.3.0}/molutils/__main__.py +1 -1
  5. {molutils-0.1.0 → molutils-0.3.0}/molutils/_core/count.py +19 -1
  6. molutils-0.3.0/molutils/_core/extract.py +94 -0
  7. molutils-0.3.0/molutils/_core/list_.py +53 -0
  8. molutils-0.3.0/molutils/_parsers/parser_pdb.py +55 -0
  9. molutils-0.3.0/molutils/_ui/__init__.py +0 -0
  10. molutils-0.3.0/molutils/_ui/app_main.py +45 -0
  11. molutils-0.3.0/molutils/_ui/app_subcommand.py +23 -0
  12. molutils-0.3.0/molutils/_ui/fy_help.fyh +49 -0
  13. molutils-0.3.0/molutils/_ui/fy_rules.fyr +32 -0
  14. molutils-0.3.0/molutils/_version.py +1 -0
  15. {molutils-0.1.0 → molutils-0.3.0}/molutils.egg-info/PKG-INFO +6 -3
  16. {molutils-0.1.0 → molutils-0.3.0}/molutils.egg-info/SOURCES.txt +5 -1
  17. molutils-0.3.0/molutils.egg-info/requires.txt +1 -0
  18. {molutils-0.1.0 → molutils-0.3.0}/setup.py +2 -2
  19. molutils-0.1.0/README.md +0 -1
  20. molutils-0.1.0/molutils/__init__.py +0 -6
  21. molutils-0.1.0/molutils/_core/extract.py +0 -28
  22. molutils-0.1.0/molutils/_ui/app.py +0 -76
  23. molutils-0.1.0/molutils/_ui/fy_help.fyh +0 -20
  24. molutils-0.1.0/molutils/_ui/fy_rules.fyr +0 -12
  25. molutils-0.1.0/molutils/_version.py +0 -1
  26. molutils-0.1.0/molutils.egg-info/requires.txt +0 -1
  27. {molutils-0.1.0 → molutils-0.3.0}/LICENSE.md +0 -0
  28. {molutils-0.1.0 → molutils-0.3.0}/molutils/_core/__init__.py +0 -0
  29. {molutils-0.1.0/molutils/_ui → molutils-0.3.0/molutils/_parsers}/__init__.py +0 -0
  30. {molutils-0.1.0 → molutils-0.3.0}/molutils.egg-info/dependency_links.txt +0 -0
  31. {molutils-0.1.0 → molutils-0.3.0}/molutils.egg-info/entry_points.txt +0 -0
  32. {molutils-0.1.0 → molutils-0.3.0}/molutils.egg-info/top_level.txt +0 -0
  33. {molutils-0.1.0 → molutils-0.3.0}/pyproject.toml +0 -0
  34. {molutils-0.1.0 → molutils-0.3.0}/setup.cfg +0 -0
@@ -1,6 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: molutils
3
- Version: 0.1.0
3
+ Version: 0.3.0
4
+ Summary: Collection of tools for preprocessing or summarizing details from biomolecular structure files.
4
5
  Home-page: https://github.com/diegobarmor/molutils
5
6
  Author: DiegoBarMor
6
7
  Author-email: diegobarmor42@gmail.com
@@ -11,7 +12,7 @@ Classifier: Operating System :: OS Independent
11
12
  Requires-Python: >=3.10
12
13
  Description-Content-Type: text/markdown
13
14
  License-File: LICENSE.md
14
- Requires-Dist: freyacli==0.2.0
15
+ Requires-Dist: freyacli==0.3.2
15
16
  Dynamic: author
16
17
  Dynamic: author-email
17
18
  Dynamic: classifier
@@ -23,5 +24,7 @@ Dynamic: license
23
24
  Dynamic: license-file
24
25
  Dynamic: requires-dist
25
26
  Dynamic: requires-python
27
+ Dynamic: summary
26
28
 
27
- # molutils
29
+ # MolUtils
30
+ MolUtils is a collection of tools for preprocessing or summarizing details from biomolecular structure files.
@@ -0,0 +1,2 @@
1
+ # MolUtils
2
+ MolUtils is a collection of tools for preprocessing or summarizing details from biomolecular structure files.
@@ -0,0 +1,11 @@
1
+ from ._version import __version__
2
+
3
+ from ._parsers.parser_pdb import ParserPDB
4
+
5
+ from ._ui.app_subcommand import AppSubcommand
6
+
7
+ from ._core.list_ import List
8
+ from ._core.count import Count
9
+ from ._core.extract import Extract
10
+
11
+ from ._ui.app_main import AppMain
@@ -9,7 +9,7 @@ except ImportError:
9
9
 
10
10
  # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11
11
  def main():
12
- mu.App(sys.argv).run()
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
+ # //////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,55 @@
1
+ from pathlib import Path
2
+
3
+ # //////////////////////////////////////////////////////////////////////////////
4
+ class ParserPDB:
5
+ LENGTH_RECORD = 80
6
+ IDX_CHAIN_ID = 21
7
+ IDX0_RESID = 22
8
+ IDX1_RESID = 26
9
+
10
+ # --------------------------------------------------------------------------
11
+ def __init__(self, data_pdb: str):
12
+ self.data = data_pdb.splitlines()
13
+
14
+
15
+ # --------------------------------------------------------------------------
16
+ @classmethod
17
+ def from_file(cls, path_pdb: Path):
18
+ return cls(path_pdb.read_text())
19
+
20
+
21
+ # --------------------------------------------------------------------------
22
+ @classmethod
23
+ def join_lines(cls, lines: list[str]) -> str:
24
+ return '\n'.join(lines) + "\nEND"
25
+
26
+
27
+ # --------------------------------------------------------------------------
28
+ def iter_atoms(self):
29
+ return (
30
+ line for line in self.data
31
+ if line.startswith("ATOM") or line.startswith("HETATM")
32
+ )
33
+
34
+
35
+ # --------------------------------------------------------------------------
36
+ @classmethod
37
+ def safe_next(cls, gen):
38
+ try: return next(gen)
39
+ except StopIteration: raise ValueError(f"No ATOM records found in PDB file")
40
+
41
+
42
+ # --------------------------------------------------------------------------
43
+ @classmethod
44
+ def get_chainid(cls, line: str) -> str:
45
+ try: return line[cls.IDX_CHAIN_ID]
46
+ except IndexError: raise ValueError(f"Unexpected format of ATOM records in PDB file")
47
+
48
+
49
+ # --------------------------------------------------------------------------
50
+ @classmethod
51
+ def get_resid(cls, line: str) -> str:
52
+ return line[cls.IDX0_RESID:cls.IDX1_RESID].strip()
53
+
54
+
55
+ # //////////////////////////////////////////////////////////////////////////////
File without changes
@@ -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
+ # //////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,49 @@
1
+ !fyh:_ molutils is a collection of tools for preprocessing or summarizing details from biomolecular structure files.
2
+
3
+ @list
4
+ !fyh:_ Lists the unique values for different aspects of biomolecular structures.
5
+ @chains
6
+ !fyh:_ Lists the chains in a PDB file.
7
+ !fyh:path_in Path of a PDB file.
8
+ !fyh:first_only Use this flag for displaying only the first chain of the structure.
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
+ !@
14
+ !@
15
+
16
+ @count
17
+ !fyh:_ Provides counts for different aspects of biomolecular structures.
18
+ @models
19
+ !fyh:_ Counts the number of models in a PDB file.
20
+ !fyh:path_in Path of a PDB file.
21
+ !@
22
+ !@
23
+
24
+ @extract
25
+ !fyh:_ Extract specific sections of data from biomolecular structures.
26
+ @models
27
+ !fyh:_ Extracts the models in a PDB file into separate files.
28
+ !use:_extract
29
+ !fyh:first_only Use this flag for extracting only the first model of the structure and disregard the rest.
30
+ !@
31
+ @chains
32
+ !fyh:_ Extracts the chains in a PDB file into separate files.
33
+ !use:_extract
34
+ !fyh:first_only Use this flag for extracting only the first chain of the structure and disregard the rest.
35
+ !@
36
+ !@
37
+
38
+ @select
39
+ !fyh:_ Select specific atoms with a custom query (MDAnalysis format) and save them into a file. Requires MDAnalysis.
40
+ !fyh:query Query for selecting the atoms of interest. Must follow MDAnalysis format
41
+ !fyh:path_in Path of the structure file whose atoms will be selected. Can be anything supported by MDanalysis.
42
+ !fyh:path_out Path for the output selected atoms. Can be anything supported by MDanalysis.
43
+ !@
44
+
45
+ !def _extract
46
+ !fyh:path_in Path of a PDB file.
47
+ !fyh:folder_out Path of the directory where to place the unpacked structures.
48
+ If not provided, the parent directory of the input PDB file will be used.
49
+ !fed
@@ -0,0 +1,32 @@
1
+ @list
2
+ @chains
3
+ path_in[]1.PATH
4
+ ~first_only[f,first-only]
5
+ !@
6
+ @resids
7
+ path_in[]1.PATH
8
+ !@
9
+ !@
10
+
11
+ @count
12
+ @models
13
+ path_in[]1.PATH
14
+ !@
15
+ !@
16
+
17
+ @extract
18
+ @models !use:_extract !@
19
+ @chains !use:_extract !@
20
+ !@
21
+
22
+ @select
23
+ query[]1.STR
24
+ path_in[]1.PATH
25
+ path_out[]1.PATH
26
+ !@
27
+
28
+ !def _extract
29
+ path_in[]1.PATH
30
+ ~folder_out[]1.PATH
31
+ ~first_only[f,first-only]
32
+ !fed
@@ -0,0 +1 @@
1
+ __version__ = "0.3.0"
@@ -1,6 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: molutils
3
- Version: 0.1.0
3
+ Version: 0.3.0
4
+ Summary: Collection of tools for preprocessing or summarizing details from biomolecular structure files.
4
5
  Home-page: https://github.com/diegobarmor/molutils
5
6
  Author: DiegoBarMor
6
7
  Author-email: diegobarmor42@gmail.com
@@ -11,7 +12,7 @@ Classifier: Operating System :: OS Independent
11
12
  Requires-Python: >=3.10
12
13
  Description-Content-Type: text/markdown
13
14
  License-File: LICENSE.md
14
- Requires-Dist: freyacli==0.2.0
15
+ Requires-Dist: freyacli==0.3.2
15
16
  Dynamic: author
16
17
  Dynamic: author-email
17
18
  Dynamic: classifier
@@ -23,5 +24,7 @@ Dynamic: license
23
24
  Dynamic: license-file
24
25
  Dynamic: requires-dist
25
26
  Dynamic: requires-python
27
+ Dynamic: summary
26
28
 
27
- # molutils
29
+ # MolUtils
30
+ MolUtils is a collection of tools for preprocessing or summarizing details from biomolecular structure files.
@@ -14,7 +14,11 @@ molutils.egg-info/top_level.txt
14
14
  molutils/_core/__init__.py
15
15
  molutils/_core/count.py
16
16
  molutils/_core/extract.py
17
+ molutils/_core/list_.py
18
+ molutils/_parsers/__init__.py
19
+ molutils/_parsers/parser_pdb.py
17
20
  molutils/_ui/__init__.py
18
- molutils/_ui/app.py
21
+ molutils/_ui/app_main.py
22
+ molutils/_ui/app_subcommand.py
19
23
  molutils/_ui/fy_help.fyh
20
24
  molutils/_ui/fy_rules.fyr
@@ -0,0 +1 @@
1
+ freyacli==0.3.2
@@ -7,7 +7,7 @@ exec(Path("molutils/_version.py").read_text())
7
7
  setup(
8
8
  name="molutils",
9
9
  version=__version__,
10
- description="",
10
+ description="Collection of tools for preprocessing or summarizing details from biomolecular structure files.",
11
11
  keywords="",
12
12
  long_description=open("README.md").read(),
13
13
  long_description_content_type="text/markdown",
@@ -21,7 +21,7 @@ setup(
21
21
  "_ui/fy_rules.fyr", "_ui/fy_help.fyh",
22
22
  ],
23
23
  },
24
- install_requires=["freyacli==0.2.0"],
24
+ install_requires=["freyacli==0.3.2"],
25
25
  entry_points={
26
26
  "console_scripts": [
27
27
  "molutils=molutils.__main__:main",
molutils-0.1.0/README.md DELETED
@@ -1 +0,0 @@
1
- # molutils
@@ -1,6 +0,0 @@
1
- from ._version import __version__
2
-
3
- from ._core.count import Count
4
- from ._core.extract import Extract
5
-
6
- from ._ui.app import App
@@ -1,28 +0,0 @@
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
- # //////////////////////////////////////////////////////////////////////////////
@@ -1,76 +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 == "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
- # //////////////////////////////////////////////////////////////////////////////
@@ -1,20 +0,0 @@
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
- !@
@@ -1,12 +0,0 @@
1
- @count
2
- @models
3
- path_pdb[]1.PATH
4
- !@
5
- !@
6
- @extract
7
- @models
8
- path_pdb[]1.PATH
9
- ~folder_out[]1.PATH
10
- ~first_only[f,first-only]
11
- !@
12
- !@
@@ -1 +0,0 @@
1
- __version__ = "0.1.0"
@@ -1 +0,0 @@
1
- freyacli==0.2.0
File without changes
File without changes
File without changes