molutils 0.4.0__tar.gz → 0.6.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 (33) hide show
  1. {molutils-0.4.0 → molutils-0.6.0}/PKG-INFO +3 -3
  2. {molutils-0.4.0 → molutils-0.6.0}/molutils/__init__.py +1 -3
  3. molutils-0.6.0/molutils/_core/count.py +110 -0
  4. molutils-0.6.0/molutils/_core/extract.py +111 -0
  5. {molutils-0.4.0 → molutils-0.6.0}/molutils/_core/list_.py +12 -13
  6. molutils-0.6.0/molutils/_core/remove.py +50 -0
  7. {molutils-0.4.0 → molutils-0.6.0}/molutils/_ui/app_main.py +13 -5
  8. molutils-0.6.0/molutils/_ui/fy_help.fyh +98 -0
  9. {molutils-0.4.0 → molutils-0.6.0}/molutils/_ui/fy_rules.fyr +28 -1
  10. molutils-0.6.0/molutils/_version.py +1 -0
  11. {molutils-0.4.0 → molutils-0.6.0}/molutils.egg-info/PKG-INFO +3 -3
  12. {molutils-0.4.0 → molutils-0.6.0}/molutils.egg-info/SOURCES.txt +1 -3
  13. molutils-0.6.0/molutils.egg-info/requires.txt +2 -0
  14. {molutils-0.4.0 → molutils-0.6.0}/setup.py +4 -1
  15. molutils-0.4.0/molutils/_core/count.py +0 -38
  16. molutils-0.4.0/molutils/_core/extract.py +0 -123
  17. molutils-0.4.0/molutils/_parsers/chain_resid.py +0 -34
  18. molutils-0.4.0/molutils/_parsers/parser_pdb.py +0 -55
  19. molutils-0.4.0/molutils/_ui/__init__.py +0 -0
  20. molutils-0.4.0/molutils/_ui/fy_help.fyh +0 -61
  21. molutils-0.4.0/molutils/_version.py +0 -1
  22. molutils-0.4.0/molutils.egg-info/requires.txt +0 -1
  23. {molutils-0.4.0 → molutils-0.6.0}/LICENSE.md +0 -0
  24. {molutils-0.4.0 → molutils-0.6.0}/README.md +0 -0
  25. {molutils-0.4.0 → molutils-0.6.0}/molutils/__main__.py +0 -0
  26. {molutils-0.4.0 → molutils-0.6.0}/molutils/_core/__init__.py +0 -0
  27. {molutils-0.4.0/molutils/_parsers → molutils-0.6.0/molutils/_ui}/__init__.py +0 -0
  28. {molutils-0.4.0 → molutils-0.6.0}/molutils/_ui/app_subcommand.py +0 -0
  29. {molutils-0.4.0 → molutils-0.6.0}/molutils.egg-info/dependency_links.txt +0 -0
  30. {molutils-0.4.0 → molutils-0.6.0}/molutils.egg-info/entry_points.txt +0 -0
  31. {molutils-0.4.0 → molutils-0.6.0}/molutils.egg-info/top_level.txt +0 -0
  32. {molutils-0.4.0 → molutils-0.6.0}/pyproject.toml +0 -0
  33. {molutils-0.4.0 → molutils-0.6.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: molutils
3
- Version: 0.4.0
3
+ Version: 0.6.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,14 +12,14 @@ 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.4.0
15
+ Requires-Dist: molsimple==0.1.2
16
+ Requires-Dist: freyacli==0.4.5
16
17
  Dynamic: author
17
18
  Dynamic: author-email
18
19
  Dynamic: classifier
19
20
  Dynamic: description
20
21
  Dynamic: description-content-type
21
22
  Dynamic: home-page
22
- Dynamic: keywords
23
23
  Dynamic: license
24
24
  Dynamic: license-file
25
25
  Dynamic: requires-dist
@@ -1,12 +1,10 @@
1
1
  from ._version import __version__
2
2
 
3
- from ._parsers.parser_pdb import ParserPDB
4
- from ._parsers.chain_resid import ChainResid
5
-
6
3
  from ._ui.app_subcommand import AppSubcommand
7
4
 
8
5
  from ._core.list_ import List
9
6
  from ._core.count import Count
10
7
  from ._core.extract import Extract
8
+ from ._core.remove import Remove
11
9
 
12
10
  from ._ui.app_main import AppMain
@@ -0,0 +1,110 @@
1
+ from pathlib import Path
2
+
3
+ import molsimple as ms
4
+ import freyacli as fy
5
+ import molutils as mu
6
+
7
+ # //////////////////////////////////////////////////////////////////////////////
8
+ class Count(mu.AppSubcommand):
9
+ # -------------------------------------------------------------------------- UI SECTION
10
+ def run(self):
11
+ command = self.main.subcommands.pop(0)
12
+
13
+ if command == "models" : return self.app_count_models()
14
+ if command == "chains" : return self.app_count_chains()
15
+ if command == "residues": return self.app_count_residues()
16
+ if command == "frames" : return self.app_count_frames()
17
+ if command == "altlocs" : return self.app_count_altlocs()
18
+
19
+ raise ValueError(f"Unknown command: {command}")
20
+
21
+
22
+ # --------------------------------------------------------------------------
23
+ def app_count_models(self):
24
+ path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
25
+ print(mu.Count.models(ms.System.read_pdb(path_in)))
26
+
27
+
28
+ # --------------------------------------------------------------------------
29
+ def app_count_chains(self):
30
+ path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
31
+ print(mu.Count.chains(ms.System.read_pdb(path_in)))
32
+
33
+
34
+ # --------------------------------------------------------------------------
35
+ def app_count_residues(self):
36
+ path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
37
+ print(mu.Count.residues(ms.System.read_pdb(path_in)))
38
+
39
+
40
+ # --------------------------------------------------------------------------
41
+ def app_count_frames(self):
42
+ path_struct = self.main.get_arg_path("path_struct", assertion = fy.PathAssertion.FILE_IN)
43
+ path_traj = self.main.get_arg_path("path_traj",
44
+ assertion = fy.PathAssertion.FILE_IN, allow_none = True
45
+ )
46
+
47
+ import MDAnalysis as mda
48
+ args_traj = [str(path_traj)] if path_traj is not None else []
49
+ u = mda.Universe(str(path_struct), *args_traj)
50
+
51
+ nframes_valid, _ = mu.Count.frames(u)
52
+ print(f"{nframes_valid}")
53
+
54
+
55
+
56
+ # --------------------------------------------------------------------------
57
+ def app_count_altlocs(self):
58
+ path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
59
+ print(mu.Count.altlocs(ms.System.read_pdb(path_in)))
60
+
61
+
62
+ # -------------------------------------------------------------------------- LOGIC SECTION
63
+ @classmethod
64
+ def models(cls, system: ms.System) -> int:
65
+ return len(system.models)
66
+
67
+
68
+ # --------------------------------------------------------------------------
69
+ @classmethod
70
+ def chains(cls, system: ms.System) -> int:
71
+ return len(mu.List.chains(system, do_sort = False))
72
+
73
+
74
+ # --------------------------------------------------------------------------
75
+ @classmethod
76
+ def residues(cls, system: ms.System) -> int:
77
+ return len(mu.List.residues(system, do_sort = False))
78
+
79
+
80
+ # --------------------------------------------------------------------------
81
+ @classmethod
82
+ def frames(cls, universe) -> tuple[int, int]:
83
+ """
84
+ Requires MDAnalysis (`universe` should be an instance of `MDAnalysis.Universe`).
85
+ Returns a tuple of `(nframes_valid, nframes_expected)`, where:
86
+ - `nframes_valid`: The number of frames that could be successfully read from the trajectory.
87
+ - `nframes_expected`: The total number of frames expected based on the trajectory metadata.
88
+ """
89
+ nframes_expected = universe.trajectory.n_frames
90
+ nframes_valid = sum(1 for _ in universe.trajectory)
91
+ return nframes_valid, nframes_expected
92
+
93
+
94
+ # --------------------------------------------------------------------------
95
+ @classmethod
96
+ def altlocs(cls, system: ms.System) -> int:
97
+ parts_with_altloc: set[tuple[str, str]] = set()
98
+
99
+ for particle in system.particles:
100
+ if not particle.altloc: continue
101
+
102
+ key = (particle.get_chain_resid().get_dotstr(), particle.name)
103
+ if key in parts_with_altloc: continue
104
+
105
+ parts_with_altloc.add(key)
106
+
107
+ return len(parts_with_altloc)
108
+
109
+
110
+ # //////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,111 @@
1
+ from pathlib import Path
2
+ from collections import defaultdict
3
+
4
+ import molsimple as ms
5
+ import freyacli as fy
6
+ import molutils as mu
7
+
8
+ # //////////////////////////////////////////////////////////////////////////////
9
+ class Extract(mu.AppSubcommand):
10
+ # -------------------------------------------------------------------------- UI SECTION
11
+ def run(self):
12
+ command = self.main.subcommands.pop(0)
13
+
14
+ if command == "models" : return self.app_extract_models()
15
+ if command == "chains" : return self.app_extract_chains()
16
+ if command == "residue": return self.app_extract_residue()
17
+ if command == "frames" : return self.app_extract_frames()
18
+
19
+ raise ValueError(f"Unknown command: {command}")
20
+
21
+ # --------------------------------------------------------------------------
22
+ def app_extract_models(self):
23
+ path_in, folder_out = self._io_filein_dirout()
24
+ first_only = self.main.get_arg_bool("first_only")
25
+
26
+ for i, model in enumerate(ms.System.read_pdb(path_in).models):
27
+ path_out = folder_out / f"{path_in.stem}.m{i:03}.pdb"
28
+ model.save(path_out)
29
+ if first_only: break
30
+
31
+
32
+ # --------------------------------------------------------------------------
33
+ def app_extract_chains(self):
34
+ path_in, folder_out = self._io_filein_dirout()
35
+ first_only = self.main.get_arg_bool("first_only")
36
+
37
+ system = ms.System.read_pdb(path_in)
38
+ chain_ids = mu.List.chains(system, do_sort = False)
39
+
40
+ for chain_id in chain_ids:
41
+ path_out = folder_out / f"{path_in.stem}.{chain_id}.pdb"
42
+ system.particles.select_chainid(chain_id).save(path_out)
43
+ if first_only: break
44
+
45
+
46
+ # --------------------------------------------------------------------------
47
+ def app_extract_residue(self):
48
+ path_in, folder_out = self._io_filein_dirout()
49
+ residue_dotstr = self.main.get_arg_str("residue")
50
+
51
+ pdb = ms.System.read_pdb(path_in)
52
+ chres = ms.ChainResid.from_dotstr(residue_dotstr)
53
+ extracted = pdb.particles.select_chain_resid(chres)
54
+ extracted.save(folder_out / f"{path_in.stem}.{residue_dotstr}.pdb")
55
+
56
+
57
+ # --------------------------------------------------------------------------
58
+ def app_extract_frames(self):
59
+ path_struct, folder_out = self._io_filein_dirout(key_in = "path_struct")
60
+ path_traj = self.main.get_arg_path("path_traj",
61
+ assertion = fy.PathAssertion.FILE_IN, allow_none = True
62
+ )
63
+ frames = self.main.get_arg_int("frames", is_list = True)
64
+ unpack = self.main.get_arg_bool("unpack")
65
+ mu.Extract.frames(path_struct, path_traj, folder_out, frames, unpack)
66
+
67
+
68
+ # --------------------------------------------------------------------------
69
+ @classmethod
70
+ def frames(cls,
71
+ path_struct: Path, path_traj: Path | None, folder_out: Path,
72
+ frames: list[int] = None, unpack: bool = False
73
+ ) -> None:
74
+ """Note: This method directly saves the specified frames instead of returning them."""
75
+ import MDAnalysis as mda
76
+
77
+ args_traj = [str(path_traj)] if path_traj is not None else []
78
+ u = mda.Universe(str(path_struct), *args_traj)
79
+
80
+ if frames is not None and len(frames) == 1:
81
+ unpack = True
82
+
83
+ if unpack:
84
+ if frames is None: frames = range(u.trajectory.n_frames)
85
+ for frame in frames:
86
+ u.trajectory[frame]
87
+ path_pdb_out = folder_out / f"{path_struct.stem}.{frame:04}.pdb"
88
+ u.atoms.write(str(path_pdb_out))
89
+ return
90
+
91
+ if path_traj is None:
92
+ ### save a struct file separately, useful when the input file
93
+ ### had both the struct and traj data inside (e.g. XYZ)
94
+ path_pdb_out = folder_out / f"{path_struct.stem}.sliced.pdb"
95
+ u.atoms.write(str(path_pdb_out))
96
+
97
+ path_xtc_out = folder_out / f"{path_struct.stem}.sliced.xtc"
98
+ u.atoms.write(str(path_xtc_out), frames = "all" if frames is None else frames)
99
+ return
100
+
101
+
102
+ # --------------------------------------------------------------------------
103
+ def _io_filein_dirout(self, key_in = "path_in") -> tuple[Path, Path]:
104
+ path_in = self.main.get_arg_path(key_in, assertion = fy.PathAssertion.FILE_IN)
105
+ folder_out = self.main.get_arg_path("folder_out",
106
+ default = path_in.parent, assertion = fy.PathAssertion.DIR_OUT
107
+ )
108
+ return path_in, folder_out
109
+
110
+
111
+ # //////////////////////////////////////////////////////////////////////////////
@@ -1,5 +1,6 @@
1
1
  from pathlib import Path
2
2
 
3
+ import molsimple as ms
3
4
  import freyacli as fy
4
5
  import molutils as mu
5
6
 
@@ -18,32 +19,30 @@ class List(mu.AppSubcommand):
18
19
  # --------------------------------------------------------------------------
19
20
  def app_list_chains(self):
20
21
  path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
21
- first_only = self.main.get_arg_bool("first_only")
22
- print(*mu.List.chains(path_in, first_only))
22
+ print(*mu.List.chains(ms.System.read_pdb(path_in), do_sort = True))
23
23
 
24
24
 
25
25
  # --------------------------------------------------------------------------
26
26
  def app_list_residues(self):
27
27
  path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
28
- print(*mu.List.residues(path_in))
28
+ print(*mu.List.residues(ms.System.read_pdb(path_in), do_sort = True))
29
29
 
30
30
 
31
31
  # -------------------------------------------------------------------------- LOGIC SECTION
32
32
  @classmethod
33
- def chains(cls, path_pdb: Path, first_only: bool = False) -> list[str]:
34
- pdb = mu.ParserPDB.from_file(path_pdb)
35
- gen_chain_ids = (mu.ParserPDB.get_chainid(line) for line in pdb.iter_atoms())
36
- if first_only: return mu.ParserPDB.safe_next(gen_chain_ids)
37
- return sorted(set(gen_chain_ids))
33
+ def chains(cls, system: ms.System, do_sort: bool = True) -> list[str]:
34
+ unique_chains = set(system.particles.get_chainids())
35
+ if do_sort: return sorted(unique_chains)
36
+ return list(unique_chains)
38
37
 
39
38
 
40
39
  # --------------------------------------------------------------------------
41
40
  @classmethod
42
- def residues(cls, path_pdb: Path) -> list[str]:
43
- """Returns list of unique residue identifiers in the format "chainid.resid"."""
44
- pdb = mu.ParserPDB.from_file(path_pdb)
45
- gen_residues = (mu.ChainResid.from_pdb(line).get_dotstr() for line in pdb.iter_atoms())
46
- return sorted(set(gen_residues))
41
+ def residues(cls, system: ms.System, do_sort: bool = True) -> list[str]:
42
+ """Returns a list of unique residue identifiers in the format "chainid.resid"."""
43
+ unique_residues = set(part.get_chain_resid().get_dotstr() for part in system)
44
+ if do_sort: return sorted(unique_residues)
45
+ return list(unique_residues)
47
46
 
48
47
 
49
48
  # //////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,50 @@
1
+ from pathlib import Path
2
+
3
+ import molsimple as ms
4
+ import freyacli as fy
5
+ import molutils as mu
6
+
7
+ # //////////////////////////////////////////////////////////////////////////////
8
+ class Remove(mu.AppSubcommand):
9
+ # -------------------------------------------------------------------------- UI SECTION
10
+ def run(self):
11
+ command = self.main.subcommands.pop(0)
12
+
13
+ if command == "altlocs" : return self.app_remove_altlocs()
14
+
15
+ raise ValueError(f"Unknown command: {command}")
16
+
17
+
18
+ # --------------------------------------------------------------------------
19
+ def app_remove_altlocs(self):
20
+ path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
21
+ path_out = self.main.get_arg_path("path_out", assertion = fy.PathAssertion.FILE_OUT)
22
+ mu.Remove.altlocs(path_in).save(path_out)
23
+
24
+
25
+ # --------------------------------------------------------------------------
26
+ @classmethod
27
+ def altlocs(cls, path_pdb: Path) -> ms.ParticleGroup:
28
+ pdb = ms.System.read_pdb(path_pdb)
29
+
30
+ out: list[ms.Particle] = []
31
+ seen_altlocs = set()
32
+ for particle in pdb.particles:
33
+ if particle.altloc == "":
34
+ out.append(particle)
35
+ continue
36
+
37
+ chres = particle.get_chain_resid().get_dotstr()
38
+ name = particle.name
39
+
40
+ key = (chres, name)
41
+ if key in seen_altlocs: continue
42
+
43
+ seen_altlocs.add(key)
44
+ particle.altloc = ""
45
+ out.append(particle)
46
+
47
+ return ms.ParticleGroup(out)
48
+
49
+
50
+ # //////////////////////////////////////////////////////////////////////////////
@@ -1,5 +1,6 @@
1
1
  from pathlib import Path
2
2
 
3
+ import molsimple as ms
3
4
  import freyacli as fy
4
5
  import molutils as mu
5
6
 
@@ -25,6 +26,7 @@ class AppMain(fy.App):
25
26
  if command == "list" : return mu.List(self).run()
26
27
  if command == "count" : return mu.Count(self).run()
27
28
  if command == "extract": return mu.Extract(self).run()
29
+ if command == "remove" : return mu.Remove(self).run()
28
30
  if command == "select" : return self._run_select()
29
31
  if command == "merge" : return self._run_merge()
30
32
  raise ValueError(f"Unknown command: {command}")
@@ -35,20 +37,26 @@ class AppMain(fy.App):
35
37
  query = self.get_arg_str("query")
36
38
  path_in = self.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
37
39
  path_out = self.get_arg_path("path_out", assertion = fy.PathAssertion.FILE_OUT)
40
+ paths_traj = self.get_arg_path("paths_traj", assertion = fy.PathAssertion.FILE_OUT,
41
+ allow_none = True, is_list = True
42
+ )
38
43
 
39
44
  import MDAnalysis as mda
40
45
  mda.Universe(path_in).select_atoms(query).write(path_out)
41
46
 
47
+ if paths_traj == [None]: return
48
+
49
+ path_traj_in, path_traj_out = paths_traj
50
+ u = mda.Universe(path_in, path_traj_in)
51
+ u.select_atoms(query).write(str(path_traj_out), frames = "all")
52
+
42
53
 
43
54
  # --------------------------------------------------------------------------
44
55
  def _run_merge(self):
45
56
  paths_in = self.get_arg_path("paths_in", assertion = fy.PathAssertion.FILE_IN, is_list = True)
46
57
  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)
58
+ pgroups = (ms.System.read_pdb(path_in).particles for path_in in paths_in)
59
+ ms.ParticleGroup((p for pgroup in pgroups for p in pgroup)).save(path_out)
52
60
 
53
61
 
54
62
  # //////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,98 @@
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
+ !@
9
+ @residues
10
+ !fyh:_ Lists the residues in a PDB file in the format "chainid.resid".
11
+ !fyh:path_in Path of a PDB file.
12
+ !@
13
+ !@
14
+
15
+ @count
16
+ !fyh:_ Provides counts for different aspects of biomolecular structures.
17
+ @models
18
+ !fyh:_ Counts the number of models in a PDB file.
19
+ !fyh:path_in Path of a PDB file.
20
+ !@
21
+ @chains
22
+ !fyh:_ Counts the number of chains in a PDB file.
23
+ !fyh:path_in Path of a PDB file.
24
+ !@
25
+ @residues
26
+ !fyh:_ Counts the number of residues in a PDB file in the format "chainid.resid".
27
+ !fyh:path_in Path of a PDB file.
28
+ !@
29
+ @frames
30
+ !fyh:_ Counts the number of frames in a trajectory.
31
+ Reports both the expected number of frames (i.e. u.trajectory.n_frames) and the number of actual valid frames.
32
+ These are reported as "valid/expected" and might differ in some formats, like in XYZ.
33
+ Requires MDAnalysis.
34
+ !fyh:path_struct Path of the structure file (e.g. PDB file). Can be anything supported by MDanalysis.
35
+ If the file also contains the trajectory data (e.g. XYZ file), then "path_traj" can be ommitted.
36
+ !fyh:path_traj Path of the trajectory file (e.g. XTC file). Can be anything supported by MDanalysis.
37
+ !@
38
+ @altlocs
39
+ !fyh:_ Counts the number of atoms/heteroatoms in a PDB file that contain alternate locations (altloc).
40
+ Only counts one per atom, disregarding how many alternate locations it has.
41
+ !fyh:path_in Path of a PDB file.
42
+ !@
43
+ !@
44
+
45
+ @extract
46
+ !fyh:_ Extract specific sections of data from biomolecular structures.
47
+ @models
48
+ !fyh:_ Extracts the models in a PDB file into separate files.
49
+ !use:_io_filein_dirout
50
+ !fyh:first_only Use this flag for extracting only the first model of the structure and disregard the rest.
51
+ !@
52
+ @chains
53
+ !fyh:_ Extracts the chains in a PDB file into separate files.
54
+ !use:_io_filein_dirout
55
+ !fyh:first_only Use this flag for extracting only the first chain of the structure and disregard the rest.
56
+ !@
57
+ @residue
58
+ !fyh:_ Extract a specific residue from a PDB file into a separate file.
59
+ !use:_io_filein_dirout
60
+ !fyh:residue Residue to extract, in the format "chainid.resid".
61
+ !@
62
+ @frames
63
+ !fyh:_ Extract specific frames from a PDB file into separate file(s).
64
+ Requires MDAnalysis.
65
+ !fyh:path_struct Path of the structure file (e.g. PDB file). Can be anything supported by MDanalysis.
66
+ If the file also contains the trajectory data (e.g. XYZ file), then "path_traj" can be ommitted.
67
+ In this case, an additional structure file (a copy of the first frame) may be exported for convenience.
68
+ !fyh:path_traj Path of the trajectory file (e.g. XTC file). Can be anything supported by MDanalysis.
69
+ !fyh:folder_out Path of the directory where to place the unpacked structure(s).
70
+ If not provided, the parent directory of the input PDB file will be used.
71
+ !fyh:frames Frame indices to extract. If no frames are specified, all frames are extracted.
72
+ If only 1 frame is specified, the frame is exported to PDB (regardless of the "unpack" flag).
73
+ !fyh:unpack When used, the specified frames will be unpacked into single PDB files.
74
+ Otherwise, the frames are exported into a single XTC file.
75
+ !@
76
+ !@
77
+
78
+ @select
79
+ !fyh:_ Select specific atoms with a custom query (MDAnalysis format) and save them into a file. Requires MDAnalysis.
80
+ !fyh:query Query for selecting the atoms of interest. Must follow MDAnalysis format
81
+ !fyh:path_in Path of the structure file whose atoms will be selected. Can be anything supported by MDanalysis.
82
+ !fyh:path_out Path for the output selected atoms. Can be anything supported by MDanalysis.
83
+ !fyh:paths_traj Input and output paths for an optional trajectory.
84
+ The selection will be applied for all frames of the selection accordingly.
85
+ !@
86
+
87
+ @merge
88
+ !fyh:_ Merge structures from multiple PDB files into a single PDB file.
89
+ !fyh:paths_in List of PDB file paths with the input structures to be merged.
90
+ At least one PDB file must be provided.
91
+ !fyh:path_out Path where to save the merged PDB structure.
92
+ !@
93
+
94
+ !def _io_filein_dirout
95
+ !fyh:path_in Path of a PDB file.
96
+ !fyh:folder_out Path of the directory where to place the unpacked structure(s).
97
+ If not provided, the parent directory of the input PDB file will be used.
98
+ !fed
@@ -1,7 +1,6 @@
1
1
  @list
2
2
  @chains
3
3
  path_in[]1.PATH
4
- ~first_only[f,first-only]
5
4
  !@
6
5
  @residues
7
6
  path_in[]1.PATH
@@ -12,6 +11,19 @@
12
11
  @models
13
12
  path_in[]1.PATH
14
13
  !@
14
+ @chains
15
+ path_in[]1.PATH
16
+ !@
17
+ @residues
18
+ path_in[]1.PATH
19
+ !@
20
+ @frames
21
+ path_struct[]1.PATH
22
+ ~path_traj[]1.PATH
23
+ !@
24
+ @altlocs
25
+ path_in[]1.PATH
26
+ !@
15
27
  !@
16
28
 
17
29
  @extract
@@ -28,12 +40,27 @@
28
40
  residue[]1.STR
29
41
  ~folder_out[o,out]1.PATH
30
42
  !@
43
+ @frames
44
+ path_struct[]1.PATH
45
+ ~path_traj[]1.PATH
46
+ ~folder_out[o,out]1.PATH
47
+ ~frames[f,frames]1+.INT
48
+ ~unpack[u,unpack]
49
+ !@
50
+ !@
51
+
52
+ @remove
53
+ @altlocs
54
+ path_in[]1.PATH
55
+ path_out[]1.PATH
56
+ !@
31
57
  !@
32
58
 
33
59
  @select
34
60
  query[]1.STR
35
61
  path_in[]1.PATH
36
62
  path_out[]1.PATH
63
+ ~paths_traj[t,traj]2.PATH
37
64
  !@
38
65
 
39
66
  @merge
@@ -0,0 +1 @@
1
+ __version__ = "0.6.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: molutils
3
- Version: 0.4.0
3
+ Version: 0.6.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,14 +12,14 @@ 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.4.0
15
+ Requires-Dist: molsimple==0.1.2
16
+ Requires-Dist: freyacli==0.4.5
16
17
  Dynamic: author
17
18
  Dynamic: author-email
18
19
  Dynamic: classifier
19
20
  Dynamic: description
20
21
  Dynamic: description-content-type
21
22
  Dynamic: home-page
22
- Dynamic: keywords
23
23
  Dynamic: license
24
24
  Dynamic: license-file
25
25
  Dynamic: requires-dist
@@ -15,9 +15,7 @@ molutils/_core/__init__.py
15
15
  molutils/_core/count.py
16
16
  molutils/_core/extract.py
17
17
  molutils/_core/list_.py
18
- molutils/_parsers/__init__.py
19
- molutils/_parsers/chain_resid.py
20
- molutils/_parsers/parser_pdb.py
18
+ molutils/_core/remove.py
21
19
  molutils/_ui/__init__.py
22
20
  molutils/_ui/app_main.py
23
21
  molutils/_ui/app_subcommand.py
@@ -0,0 +1,2 @@
1
+ molsimple==0.1.2
2
+ freyacli==0.4.5
@@ -21,7 +21,10 @@ setup(
21
21
  "_ui/fy_rules.fyr", "_ui/fy_help.fyh",
22
22
  ],
23
23
  },
24
- install_requires=["freyacli==0.4.0"],
24
+ install_requires=[
25
+ "molsimple==0.1.2",
26
+ "freyacli==0.4.5",
27
+ ],
25
28
  entry_points={
26
29
  "console_scripts": [
27
30
  "molutils=molutils.__main__:main",
@@ -1,38 +0,0 @@
1
- from pathlib import Path
2
-
3
- import freyacli as fy
4
- import molutils as mu
5
-
6
- # //////////////////////////////////////////////////////////////////////////////
7
- class Count(mu.AppSubcommand):
8
- # -------------------------------------------------------------------------- UI SECTION
9
- def run(self):
10
- command = self.main.subcommands.pop(0)
11
-
12
- if command == "models": return self.app_count_models()
13
-
14
- raise ValueError(f"Unknown command: {command}")
15
-
16
-
17
- # --------------------------------------------------------------------------
18
- def app_count_models(self):
19
- path_in = self.main.get_arg_path("path_in", assertion = fy.PathAssertion.FILE_IN)
20
- print(mu.Count.models(path_in))
21
-
22
-
23
- # -------------------------------------------------------------------------- LOGIC SECTION
24
- @classmethod
25
- def models(cls, path_pdb: Path) -> int:
26
- data = path_pdb.read_text()
27
- return max(1, cls._count_substring('\n'+data, "\nMODEL"))
28
-
29
-
30
- # --------------------------------------------------------------------------
31
- @staticmethod
32
- def _count_substring(string: str, substring: str) -> int:
33
- """Counts the number of occurrences of `substring` in `string`."""
34
- replaced = string.replace(substring, "")
35
- return (len(string) - len(replaced)) // len(substring)
36
-
37
-
38
- # //////////////////////////////////////////////////////////////////////////////
@@ -1,123 +0,0 @@
1
- from collections import defaultdict
2
-
3
- import freyacli as fy
4
- import molutils as mu
5
-
6
- # //////////////////////////////////////////////////////////////////////////////
7
- class Extract(mu.AppSubcommand):
8
- # -------------------------------------------------------------------------- UI SECTION
9
- def run(self):
10
- command = self.main.subcommands.pop(0)
11
-
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()
15
-
16
- raise ValueError(f"Unknown command: {command}")
17
-
18
- # --------------------------------------------------------------------------
19
- def app_extract_models(self):
20
- path_in, folder_out = self._io_filein_dirout()
21
- data_pdb = path_in.read_text()
22
-
23
- if self.main.get_arg_bool("first_only"):
24
- _, model = mu.Extract.next_model(data_pdb)
25
- path_out = folder_out / f"{path_in.stem}.m0.pdb"
26
- path_out.write_text(model)
27
- return
28
-
29
- for i, model in enumerate(mu.Extract.iter_models(data_pdb)):
30
- path_out = folder_out / f"{path_in.stem}.m{i:03}.pdb"
31
- path_out.write_text(model)
32
-
33
-
34
- # --------------------------------------------------------------------------
35
- def app_extract_chains(self):
36
- path_in, folder_out = self._io_filein_dirout()
37
- data_pdb = path_in.read_text()
38
-
39
- chains = mu.Extract.split_chains(data_pdb)
40
-
41
- chain_ids = mu.List.chains(path_in, first_only = True) \
42
- if self.main.get_arg_bool("first_only") else chains.keys()
43
-
44
- for chain_id in chain_ids:
45
- path_out = folder_out / f"{path_in.stem}.{chain_id}.pdb"
46
- path_out.write_text(chains[chain_id])
47
-
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
-
62
- # -------------------------------------------------------------------------- LOGIC SECTION
63
- @classmethod
64
- def next_model(cls, data: str, start: int = 0) -> tuple[int, str]:
65
- idx_0 = data.find("\nMODEL", start)
66
- if idx_0 == -1: return -1, data
67
-
68
- idx_1 = data.find("\nENDMDL", idx_0)
69
- if idx_1 == -1: return -1, data[idx_0:]
70
-
71
- idx_1 += len("\nENDMDL")
72
- return idx_1, data[idx_0:idx_1] + "\nEND"
73
-
74
-
75
- # --------------------------------------------------------------------------
76
- @classmethod
77
- def iter_models(cls, data: str):
78
- while data:
79
- idx, model = cls.next_model(data)
80
- yield model
81
- if idx == -1: break
82
- data = data[idx:]
83
-
84
-
85
- # --------------------------------------------------------------------------
86
- @classmethod
87
- def split_chains(cls, data: str) -> dict[str, str]:
88
- pdb = mu.ParserPDB(data)
89
- chains = defaultdict(list)
90
- for line in pdb.iter_atoms():
91
- chain_id = mu.ParserPDB.get_chainid(line)
92
- chains[chain_id].append(line)
93
- return {
94
- chain_id: mu.ParserPDB.join_lines(lines)
95
- for chain_id, lines in chains.items()
96
- }
97
-
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
-
123
- # //////////////////////////////////////////////////////////////////////////////
@@ -1,34 +0,0 @@
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,55 +0,0 @@
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
@@ -1,61 +0,0 @@
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
- @residues
11
- !fyh:_ Lists the residues 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:_io_filein_dirout
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:_io_filein_dirout
34
- !fyh:first_only Use this flag for extracting only the first chain of the structure and disregard the rest.
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
- !@
41
- !@
42
-
43
- @select
44
- !fyh:_ Select specific atoms with a custom query (MDAnalysis format) and save them into a file. Requires MDAnalysis.
45
- !fyh:query Query for selecting the atoms of interest. Must follow MDAnalysis format
46
- !fyh:path_in Path of the structure file whose atoms will be selected. Can be anything supported by MDanalysis.
47
- !fyh:path_out Path for the output selected atoms. Can be anything supported by MDanalysis.
48
- !@
49
-
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
58
- !fyh:path_in Path of a PDB file.
59
- !fyh:folder_out Path of the directory where to place the unpacked structure(s).
60
- If not provided, the parent directory of the input PDB file will be used.
61
- !fed
@@ -1 +0,0 @@
1
- __version__ = "0.4.0"
@@ -1 +0,0 @@
1
- freyacli==0.4.0
File without changes
File without changes
File without changes
File without changes
File without changes