molutils 0.3.0__tar.gz → 0.4.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 (30) hide show
  1. {molutils-0.3.0 → molutils-0.4.0}/PKG-INFO +2 -2
  2. {molutils-0.3.0 → molutils-0.4.0}/molutils/__init__.py +1 -0
  3. {molutils-0.3.0 → molutils-0.4.0}/molutils/_core/count.py +2 -2
  4. {molutils-0.3.0 → molutils-0.4.0}/molutils/_core/extract.py +44 -15
  5. {molutils-0.3.0 → molutils-0.4.0}/molutils/_core/list_.py +9 -13
  6. molutils-0.4.0/molutils/_parsers/chain_resid.py +34 -0
  7. {molutils-0.3.0 → molutils-0.4.0}/molutils/_ui/app_main.py +15 -6
  8. {molutils-0.3.0 → molutils-0.4.0}/molutils/_ui/fy_help.fyh +18 -6
  9. molutils-0.4.0/molutils/_ui/fy_rules.fyr +47 -0
  10. molutils-0.4.0/molutils/_version.py +1 -0
  11. {molutils-0.3.0 → molutils-0.4.0}/molutils.egg-info/PKG-INFO +2 -2
  12. {molutils-0.3.0 → molutils-0.4.0}/molutils.egg-info/SOURCES.txt +1 -0
  13. molutils-0.4.0/molutils.egg-info/requires.txt +1 -0
  14. {molutils-0.3.0 → molutils-0.4.0}/setup.py +1 -1
  15. molutils-0.3.0/molutils/_ui/fy_rules.fyr +0 -32
  16. molutils-0.3.0/molutils/_version.py +0 -1
  17. molutils-0.3.0/molutils.egg-info/requires.txt +0 -1
  18. {molutils-0.3.0 → molutils-0.4.0}/LICENSE.md +0 -0
  19. {molutils-0.3.0 → molutils-0.4.0}/README.md +0 -0
  20. {molutils-0.3.0 → molutils-0.4.0}/molutils/__main__.py +0 -0
  21. {molutils-0.3.0 → molutils-0.4.0}/molutils/_core/__init__.py +0 -0
  22. {molutils-0.3.0 → molutils-0.4.0}/molutils/_parsers/__init__.py +0 -0
  23. {molutils-0.3.0 → molutils-0.4.0}/molutils/_parsers/parser_pdb.py +0 -0
  24. {molutils-0.3.0 → molutils-0.4.0}/molutils/_ui/__init__.py +0 -0
  25. {molutils-0.3.0 → molutils-0.4.0}/molutils/_ui/app_subcommand.py +0 -0
  26. {molutils-0.3.0 → molutils-0.4.0}/molutils.egg-info/dependency_links.txt +0 -0
  27. {molutils-0.3.0 → molutils-0.4.0}/molutils.egg-info/entry_points.txt +0 -0
  28. {molutils-0.3.0 → molutils-0.4.0}/molutils.egg-info/top_level.txt +0 -0
  29. {molutils-0.3.0 → molutils-0.4.0}/pyproject.toml +0 -0
  30. {molutils-0.3.0 → molutils-0.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: molutils
3
- Version: 0.3.0
3
+ Version: 0.4.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.2
15
+ Requires-Dist: freyacli==0.4.0
16
16
  Dynamic: author
17
17
  Dynamic: author-email
18
18
  Dynamic: classifier
@@ -1,6 +1,7 @@
1
1
  from ._version import __version__
2
2
 
3
3
  from ._parsers.parser_pdb import ParserPDB
4
+ from ._parsers.chain_resid import ChainResid
4
5
 
5
6
  from ._ui.app_subcommand import AppSubcommand
6
7
 
@@ -1,5 +1,6 @@
1
1
  from pathlib import Path
2
2
 
3
+ import freyacli as fy
3
4
  import molutils as mu
4
5
 
5
6
  # //////////////////////////////////////////////////////////////////////////////
@@ -15,8 +16,7 @@ class Count(mu.AppSubcommand):
15
16
 
16
17
  # --------------------------------------------------------------------------
17
18
  def app_count_models(self):
18
- path_in = self.main.get_arg_path("path_in")
19
- self.main.assert_file_in(path_in)
19
+ path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
20
20
  print(mu.Count.models(path_in))
21
21
 
22
22
 
@@ -1,26 +1,23 @@
1
1
  from collections import defaultdict
2
2
 
3
+ import freyacli as fy
3
4
  import molutils as mu
4
5
 
5
6
  # //////////////////////////////////////////////////////////////////////////////
6
7
  class Extract(mu.AppSubcommand):
7
8
  # -------------------------------------------------------------------------- UI SECTION
8
9
  def run(self):
9
- command = self.subcommands.pop(0)
10
+ command = self.main.subcommands.pop(0)
10
11
 
11
- if command == "models": return self.app_extract_models()
12
- if command == "chains": return self.app_extract_chains()
12
+ if command == "models" : return self.app_extract_models()
13
+ if command == "chains" : return self.app_extract_chains()
14
+ if command == "residue": return self.app_extract_residue()
13
15
 
14
16
  raise ValueError(f"Unknown command: {command}")
15
17
 
16
18
  # --------------------------------------------------------------------------
17
19
  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
-
20
+ path_in, folder_out = self._io_filein_dirout()
24
21
  data_pdb = path_in.read_text()
25
22
 
26
23
  if self.main.get_arg_bool("first_only"):
@@ -36,12 +33,7 @@ class Extract(mu.AppSubcommand):
36
33
 
37
34
  # --------------------------------------------------------------------------
38
35
  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
-
36
+ path_in, folder_out = self._io_filein_dirout()
45
37
  data_pdb = path_in.read_text()
46
38
 
47
39
  chains = mu.Extract.split_chains(data_pdb)
@@ -54,6 +46,19 @@ class Extract(mu.AppSubcommand):
54
46
  path_out.write_text(chains[chain_id])
55
47
 
56
48
 
49
+ # --------------------------------------------------------------------------
50
+ def app_extract_residue(self):
51
+ path_in, folder_out = self._io_filein_dirout()
52
+ data_pdb = path_in.read_text()
53
+
54
+ residue_dotstr = self.main.get_arg_str("residue")
55
+ chres = mu.ChainResid.from_dotstr(residue_dotstr)
56
+ extracted = mu.Extract.residue(data_pdb, chres.resid, chres.chain)
57
+
58
+ path_out = folder_out / f"{path_in.stem}.{residue_dotstr}.pdb"
59
+ path_out.write_text(extracted)
60
+
61
+
57
62
  # -------------------------------------------------------------------------- LOGIC SECTION
58
63
  @classmethod
59
64
  def next_model(cls, data: str, start: int = 0) -> tuple[int, str]:
@@ -91,4 +96,28 @@ class Extract(mu.AppSubcommand):
91
96
  }
92
97
 
93
98
 
99
+ # --------------------------------------------------------------------------
100
+ @classmethod
101
+ def residue(cls, data: str, resid: str, chain: str = None):
102
+ pdb = mu.ParserPDB(data)
103
+ gen_residue = (
104
+ line for line in pdb.iter_atoms()
105
+ if mu.ParserPDB.get_resid(line) == resid
106
+ )
107
+ if chain is not None: gen_residue = (
108
+ line for line in gen_residue
109
+ if mu.ParserPDB.get_chainid(line) == chain
110
+ )
111
+ return mu.ParserPDB.join_lines(gen_residue)
112
+
113
+
114
+ # --------------------------------------------------------------------------
115
+ def _io_filein_dirout(self):
116
+ path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
117
+ folder_out = self.main.get_arg_path("folder_out",
118
+ default = path_in.parent, assertion = fy.PathAssertion.DIR_OUT
119
+ )
120
+ return path_in, folder_out
121
+
122
+
94
123
  # //////////////////////////////////////////////////////////////////////////////
@@ -1,5 +1,6 @@
1
1
  from pathlib import Path
2
2
 
3
+ import freyacli as fy
3
4
  import molutils as mu
4
5
 
5
6
  # //////////////////////////////////////////////////////////////////////////////
@@ -9,24 +10,22 @@ class List(mu.AppSubcommand):
9
10
  command = self.main.subcommands.pop(0)
10
11
 
11
12
  if command == "chains": return self.app_list_chains()
12
- if command == "resids": return self.app_list_resids()
13
+ if command == "residues": return self.app_list_residues()
13
14
 
14
15
  raise ValueError(f"Unknown command: {command}")
15
16
 
16
17
 
17
18
  # --------------------------------------------------------------------------
18
19
  def app_list_chains(self):
19
- path_in = self.main.get_arg_path("path_in")
20
+ path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
20
21
  first_only = self.main.get_arg_bool("first_only")
21
- self.main.assert_file_in(path_in)
22
22
  print(*mu.List.chains(path_in, first_only))
23
23
 
24
24
 
25
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))
26
+ def app_list_residues(self):
27
+ path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
28
+ print(*mu.List.residues(path_in))
30
29
 
31
30
 
32
31
  # -------------------------------------------------------------------------- LOGIC SECTION
@@ -40,14 +39,11 @@ class List(mu.AppSubcommand):
40
39
 
41
40
  # --------------------------------------------------------------------------
42
41
  @classmethod
43
- def resids(cls, path_pdb: Path) -> list[str]:
42
+ def residues(cls, path_pdb: Path) -> list[str]:
44
43
  """Returns list of unique residue identifiers in the format "chainid.resid"."""
45
44
  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))
45
+ gen_residues = (mu.ChainResid.from_pdb(line).get_dotstr() for line in pdb.iter_atoms())
46
+ return sorted(set(gen_residues))
51
47
 
52
48
 
53
49
  # //////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,34 @@
1
+ import molutils as mu
2
+
3
+ # //////////////////////////////////////////////////////////////////////////////
4
+ class ChainResid:
5
+ def __init__(self, chain: str, resid: str):
6
+ self.chain = chain
7
+ self.resid = resid
8
+
9
+
10
+ # --------------------------------------------------------------------------
11
+ @classmethod
12
+ def from_pdb(cls, line: str) -> "ChainResid":
13
+ """Parses an ATOM/HETATM line (PDB format) and returns a ChainResid instance."""
14
+ return cls(mu.ParserPDB.get_chainid(line), mu.ParserPDB.get_resid(line))
15
+
16
+
17
+ # --------------------------------------------------------------------------
18
+ @classmethod
19
+ def from_dotstr(cls, dotstr: str) -> "ChainResid":
20
+ """Parses a string in the format `chainid.resid`."""
21
+ parts = dotstr.split(".")
22
+ if len(parts) != 2:
23
+ raise ValueError(f"Invalid format for ChainResid: {dotstr}. Expected format: `chainid.resid`.")
24
+ chain, resid = parts
25
+ return cls(chain, resid)
26
+
27
+
28
+ # --------------------------------------------------------------------------
29
+ def get_dotstr(self) -> str:
30
+ """Returns a string in the format `chainid.resid`."""
31
+ return f"{self.chain}.{self.resid}"
32
+
33
+
34
+ # //////////////////////////////////////////////////////////////////////////////
@@ -1,9 +1,7 @@
1
1
  from pathlib import Path
2
2
 
3
- import molutils as mu
4
-
5
3
  import freyacli as fy
6
-
4
+ import molutils as mu
7
5
 
8
6
  # //////////////////////////////////////////////////////////////////////////////
9
7
  class AppMain(fy.App):
@@ -28,18 +26,29 @@ class AppMain(fy.App):
28
26
  if command == "count" : return mu.Count(self).run()
29
27
  if command == "extract": return mu.Extract(self).run()
30
28
  if command == "select" : return self._run_select()
29
+ if command == "merge" : return self._run_merge()
31
30
  raise ValueError(f"Unknown command: {command}")
32
31
 
33
32
 
34
33
  # --------------------------------------------------------------------------
35
34
  def _run_select(self):
36
35
  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)
36
+ path_in = self.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
37
+ path_out = self.get_arg_path("path_out", assertion = fy.PathAssertion.FILE_OUT)
40
38
 
41
39
  import MDAnalysis as mda
42
40
  mda.Universe(path_in).select_atoms(query).write(path_out)
43
41
 
44
42
 
43
+ # --------------------------------------------------------------------------
44
+ def _run_merge(self):
45
+ paths_in = self.get_arg_path("paths_in", assertion = fy.PathAssertion.FILE_IN, is_list = True)
46
+ path_out = self.get_arg_path("path_out", assertion = fy.PathAssertion.FILE_OUT)
47
+ data = mu.ParserPDB.join_lines(
48
+ line for path_in in paths_in
49
+ for line in mu.ParserPDB.from_file(path_in).iter_atoms()
50
+ )
51
+ path_out.write_text(data)
52
+
53
+
45
54
  # //////////////////////////////////////////////////////////////////////////////
@@ -7,8 +7,8 @@
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".
10
+ @residues
11
+ !fyh:_ Lists the residues in a PDB file in the format "chainid.resid".
12
12
  !fyh:path_in Path of a PDB file.
13
13
  !@
14
14
  !@
@@ -25,14 +25,19 @@
25
25
  !fyh:_ Extract specific sections of data from biomolecular structures.
26
26
  @models
27
27
  !fyh:_ Extracts the models in a PDB file into separate files.
28
- !use:_extract
28
+ !use:_io_filein_dirout
29
29
  !fyh:first_only Use this flag for extracting only the first model of the structure and disregard the rest.
30
30
  !@
31
31
  @chains
32
32
  !fyh:_ Extracts the chains in a PDB file into separate files.
33
- !use:_extract
33
+ !use:_io_filein_dirout
34
34
  !fyh:first_only Use this flag for extracting only the first chain of the structure and disregard the rest.
35
35
  !@
36
+ @residue
37
+ !fyh:_ Extract a specific residue from a PDB file into a separate file.
38
+ !use:_io_filein_dirout
39
+ !fyh:residue Residue to extract, in the format "chainid.resid".
40
+ !@
36
41
  !@
37
42
 
38
43
  @select
@@ -42,8 +47,15 @@
42
47
  !fyh:path_out Path for the output selected atoms. Can be anything supported by MDanalysis.
43
48
  !@
44
49
 
45
- !def _extract
50
+ @merge
51
+ !fyh:_ Merge structures from multiple PDB files into a single PDB file.
52
+ !fyh:paths_in List of PDB file paths with the input structures to be merged.
53
+ At least one PDB file must be provided.
54
+ !fyh:path_out Path where to save the merged PDB structure.
55
+ !@
56
+
57
+ !def _io_filein_dirout
46
58
  !fyh:path_in Path of a PDB file.
47
- !fyh:folder_out Path of the directory where to place the unpacked structures.
59
+ !fyh:folder_out Path of the directory where to place the unpacked structure(s).
48
60
  If not provided, the parent directory of the input PDB file will be used.
49
61
  !fed
@@ -0,0 +1,47 @@
1
+ @list
2
+ @chains
3
+ path_in[]1.PATH
4
+ ~first_only[f,first-only]
5
+ !@
6
+ @residues
7
+ path_in[]1.PATH
8
+ !@
9
+ !@
10
+
11
+ @count
12
+ @models
13
+ path_in[]1.PATH
14
+ !@
15
+ !@
16
+
17
+ @extract
18
+ @models
19
+ !use:_io_filein_dirout
20
+ ~first_only[f,first-only]
21
+ !@
22
+ @chains
23
+ !use:_io_filein_dirout
24
+ ~first_only[f,first-only]
25
+ !@
26
+ @residue
27
+ path_in[]1.PATH
28
+ residue[]1.STR
29
+ ~folder_out[o,out]1.PATH
30
+ !@
31
+ !@
32
+
33
+ @select
34
+ query[]1.STR
35
+ path_in[]1.PATH
36
+ path_out[]1.PATH
37
+ !@
38
+
39
+ @merge
40
+ paths_in[]1+.PATH
41
+ path_out[o,out]1.PATH
42
+ !@
43
+
44
+ !def _io_filein_dirout
45
+ path_in[]1.PATH
46
+ ~folder_out[]1.PATH
47
+ !fed
@@ -0,0 +1 @@
1
+ __version__ = "0.4.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: molutils
3
- Version: 0.3.0
3
+ Version: 0.4.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.2
15
+ Requires-Dist: freyacli==0.4.0
16
16
  Dynamic: author
17
17
  Dynamic: author-email
18
18
  Dynamic: classifier
@@ -16,6 +16,7 @@ molutils/_core/count.py
16
16
  molutils/_core/extract.py
17
17
  molutils/_core/list_.py
18
18
  molutils/_parsers/__init__.py
19
+ molutils/_parsers/chain_resid.py
19
20
  molutils/_parsers/parser_pdb.py
20
21
  molutils/_ui/__init__.py
21
22
  molutils/_ui/app_main.py
@@ -0,0 +1 @@
1
+ freyacli==0.4.0
@@ -21,7 +21,7 @@ setup(
21
21
  "_ui/fy_rules.fyr", "_ui/fy_help.fyh",
22
22
  ],
23
23
  },
24
- install_requires=["freyacli==0.3.2"],
24
+ install_requires=["freyacli==0.4.0"],
25
25
  entry_points={
26
26
  "console_scripts": [
27
27
  "molutils=molutils.__main__:main",
@@ -1,32 +0,0 @@
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
@@ -1 +0,0 @@
1
- __version__ = "0.3.0"
@@ -1 +0,0 @@
1
- freyacli==0.3.2
File without changes
File without changes
File without changes
File without changes
File without changes