atomict 1.2.23__py3-none-any.whl → 1.2.24__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
atomict/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.2.23"
1
+ __version__ = "1.2.24"
@@ -0,0 +1,100 @@
1
+ import os
2
+ import logging
3
+ import click
4
+ from rich.console import Console
5
+ from ase.io import read, write
6
+ from ase.io.formats import UnknownFileTypeError
7
+ from atomict.io.formats.atraj import read_atraj, write_atraj
8
+ from atomict.io.formats.tess import read_tess, write_tess
9
+
10
+ console = Console()
11
+
12
+ @click.command()
13
+ @click.argument("input_file", required=True)
14
+ @click.argument("output_file", required=True)
15
+ def convert(input_file: str, output_file: str):
16
+ """Convert atomic structure files between supported formats (e.g. .xyz, .cif, .traj)."""
17
+ RW_FORMATS = [
18
+ 'abinit-in', 'aims', 'bundletrajectory', 'castep-cell', 'castep-geom',
19
+ 'castep-md', 'cfg', 'cif', 'crystal', 'cube', 'db', 'dftb', 'dlp4',
20
+ 'dmol-arc', 'dmol-car', 'dmol-incoor', 'eon', 'espresso-in', 'extxyz',
21
+ 'gaussian-in', 'gen', 'gpumd', 'gromacs', 'gromos', 'json', 'jsv',
22
+ 'lammps-data', 'magres', 'mustem', 'mysql', 'netcdftrajectory', 'nwchem-in',
23
+ 'onetep-in', 'postgresql', 'prismatic', 'proteindatabank', 'res',
24
+ 'rmc6f', 'struct', 'sys', 'traj', 'turbomole', 'v-sim', 'vasp',
25
+ 'vasp-xdatcar', 'xsd', 'xsf', 'xtd', 'xyz'
26
+ ]
27
+
28
+ try:
29
+ input_ext = os.path.splitext(input_file)[1].lower()[1:]
30
+ output_ext = os.path.splitext(output_file)[1].lower()[1:]
31
+
32
+ if not os.path.exists(input_file):
33
+ console.print(f"[red]Error: Input file '{input_file}' not found.[/red]")
34
+ return
35
+
36
+ traj_msgpack_formats = ["atraj", "tess"]
37
+
38
+ def _is_supported(ext: str) -> bool:
39
+ return (
40
+ ext in RW_FORMATS
41
+ or ext in traj_msgpack_formats
42
+ )
43
+
44
+ def _print_supported_error(ext: str, action: str) -> None:
45
+ console.print(f"[red]Error: Format '{ext}' is not supported for {action}.[/red]")
46
+ console.print("[yellow]Supported read/write formats include:[/yellow]")
47
+ for i in range(0, len(RW_FORMATS), 5):
48
+ console.print("[yellow] " + ", ".join(RW_FORMATS[i:i+5]) + "[/yellow]")
49
+ console.print("[yellow]Special formats: atm (msgpack), atraj (msgpack trajectory), tess (msgpack trajectory)[/yellow]")
50
+
51
+ if not _is_supported(input_ext):
52
+ _print_supported_error(input_ext, "reading")
53
+ return
54
+
55
+ if not _is_supported(output_ext):
56
+ _print_supported_error(output_ext, "writing")
57
+ return
58
+
59
+ try:
60
+ if input_ext == "atraj":
61
+ atoms, _ = read_atraj(input_file)
62
+ elif input_ext == "tess":
63
+ atoms, _ = read_tess(input_file)
64
+ else:
65
+ atoms = read(input_file, index=":")
66
+ except UnknownFileTypeError:
67
+ console.print(f"[red]Error: Unknown file type for input file '{input_file}'[/red]")
68
+ console.print(f"[yellow]The file extension '{input_ext}' is not recognized.[/yellow]")
69
+ console.print("[yellow]Make sure the file has the correct extension for its format.[/yellow]")
70
+ return
71
+ except Exception as e:
72
+ console.print(f"[red]Error reading input file '{input_file}': {str(e)}.[/red]")
73
+ console.print(f"[yellow]Make sure '{input_ext}' is a valid format and the file is not corrupted.[/yellow]")
74
+ return
75
+
76
+ try:
77
+ if output_ext == "atraj":
78
+ write_atraj(atoms, output_file)
79
+ elif output_ext == "tess":
80
+ write_tess(atoms, output_file)
81
+ else:
82
+ write(output_file, atoms)
83
+
84
+ console.print(f"[green]Successfully converted {input_file} to {output_file}[/green]")
85
+
86
+ except UnknownFileTypeError:
87
+ console.print(f"[red]Error: Unknown file type for output file '{output_file}'[/red]")
88
+ console.print(f"[yellow]The file extension '{output_ext}' is not recognized.[/yellow]")
89
+ console.print("[yellow]Make sure the file has the correct extension for its format.[/yellow]")
90
+ return
91
+ except Exception as e:
92
+ console.print(f"[red]Error writing output file '{output_file}': {str(e)}[/red]")
93
+ console.print(f"[yellow]Make sure '{output_ext}' is a valid format and you have write permissions.[/yellow]")
94
+ return
95
+
96
+ except Exception as e:
97
+ logging.debug(f"Conversion failed with error: {str(e)}", exc_info=True)
98
+ console.print(f"[red]Error during conversion: {str(e)}[/red]")
99
+ console.print("[yellow]Try running with --verbose for more detailed error information.[/yellow]")
100
+
@@ -16,12 +16,8 @@ def subsample(file_path, step):
16
16
 
17
17
  The output will be saved as {original_filename}_subsampled_{step}.traj
18
18
  """
19
- try:
20
- from ase.io import read, write
21
- from ase.io.trajectory import TrajectoryWriter
22
- except ImportError:
23
- click.echo("Error: ASE modules not found. Please install with 'pip install atomict[utils]'")
24
- raise
19
+ from ase.io import read, write
20
+ from ase.io.trajectory import TrajectoryWriter
25
21
 
26
22
  if step <= 0:
27
23
  click.echo("Error: Step must be a positive integer")
atomict/cli/main.py CHANGED
@@ -8,14 +8,9 @@ from rich.console import Console
8
8
 
9
9
  from atomict.__version__ import __version__
10
10
  from atomict.cli.commands import login, token, user
11
- from atomict.cli.ext.custom_classes import DefaultCommandGroup
12
-
13
- try:
14
- from .commands import adsorbate, catalysis, k8s, project, task, traj, upload
15
- from .commands.exploration import soec, sqs
16
- from .commands.simulation import fhiaims, kpoint, vibes
17
- except ImportError:
18
- sys.exit(1)
11
+ from .commands import k8s, project, task, traj, upload, convert
12
+ from .commands.exploration import soec, sqs
13
+ from .commands.simulation import fhiaims, kpoint
19
14
 
20
15
 
21
16
  console = Console()
@@ -41,7 +36,7 @@ def setup_logging(verbose: bool):
41
36
  )
42
37
 
43
38
 
44
- @click.group(cls=DefaultCommandGroup, invoke_without_command=True)
39
+ @click.group(invoke_without_command=True)
45
40
  @click.option(
46
41
  "-v", "--verbose", is_flag=True, default=False, help="Enable verbose output"
47
42
  )
@@ -49,124 +44,12 @@ def setup_logging(verbose: bool):
49
44
  @click.pass_context
50
45
  def cli(ctx, verbose: bool):
51
46
  """Atomic Tessellator CLI - Manage simulations and computational resources
52
-
53
- Default behavior: when called with two file arguments, converts between file formats.
54
47
  """
55
48
  setup_logging(verbose)
56
-
57
- if ctx.invoked_subcommand is None and len(sys.argv) <= 1:
49
+ if ctx.invoked_subcommand is None:
58
50
  click.echo(ctx.get_help())
59
51
 
60
52
 
61
- @cli.command(default_command=True)
62
- @click.argument("input_file", required=True)
63
- @click.argument("output_file", required=True)
64
- def convert(input_file, output_file):
65
- """Convert between atomic structure file formats using ASE
66
-
67
- Supports all formats that ASE can read/write, with special handling for .atm and .atraj files.
68
- Usage examples:
69
- tess input.cif output.xyz
70
- tess input.xyz output.atm
71
- tess input.traj output.atraj
72
-
73
- """
74
- try:
75
- import os.path
76
- from ase.io import read, write
77
- from ase.io.formats import UnknownFileTypeError
78
- from atomict.io.formats.atraj import read_atraj, write_atraj
79
- from atomict.io.formats.tess import read_tess, write_tess
80
- except ImportError:
81
- console.print("[red]Error: ASE (Atomic Simulation Environment) is required for file conversion.[/red]")
82
- console.print("[yellow]Install it with: pip install ase[/yellow]")
83
- return
84
-
85
- RW_FORMATS = [
86
- 'abinit-in', 'aims', 'bundletrajectory', 'castep-cell', 'castep-geom',
87
- 'castep-md', 'cfg', 'cif', 'crystal', 'cube', 'db', 'dftb', 'dlp4',
88
- 'dmol-arc', 'dmol-car', 'dmol-incoor', 'eon', 'espresso-in', 'extxyz',
89
- 'gaussian-in', 'gen', 'gpumd', 'gromacs', 'gromos', 'json', 'jsv',
90
- 'lammps-data', 'magres', 'mustem', 'mysql', 'netcdftrajectory', 'nwchem-in',
91
- 'onetep-in', 'postgresql', 'prismatic', 'proteindatabank', 'res',
92
- 'rmc6f', 'struct', 'sys', 'traj', 'turbomole', 'v-sim', 'vasp',
93
- 'vasp-xdatcar', 'xsd', 'xsf', 'xtd', 'xyz'
94
- ]
95
-
96
- try:
97
- input_ext = os.path.splitext(input_file)[1].lower()[1:]
98
- output_ext = os.path.splitext(output_file)[1].lower()[1:]
99
-
100
- if not os.path.exists(input_file):
101
- console.print(f"[red]Error: Input file '{input_file}' not found.[/red]")
102
- return
103
-
104
- traj_msgpack_formats = ["atraj", "tess"]
105
-
106
- def _is_supported(ext: str) -> bool:
107
- return (
108
- ext in RW_FORMATS
109
- or ext in traj_msgpack_formats
110
- )
111
-
112
- def _print_supported_error(ext: str, action: str) -> None:
113
- console.print(f"[red]Error: Format '{ext}' is not supported for {action}.[/red]")
114
- console.print("[yellow]Supported read/write formats include:[/yellow]")
115
- for i in range(0, len(RW_FORMATS), 5):
116
- console.print("[yellow] " + ", ".join(RW_FORMATS[i:i+5]) + "[/yellow]")
117
- console.print("[yellow]Special formats: atm (msgpack), atraj (msgpack trajectory), tess (msgpack trajectory)[/yellow]")
118
-
119
- if not _is_supported(input_ext):
120
- _print_supported_error(input_ext, "reading")
121
- return
122
-
123
- if not _is_supported(output_ext):
124
- _print_supported_error(output_ext, "writing")
125
- return
126
-
127
- try:
128
- if input_ext == "atraj":
129
- atoms, _ = read_atraj(input_file)
130
- elif input_ext == "tess":
131
- atoms, _ = read_tess(input_file)
132
- else:
133
- atoms = read(input_file, index=":")
134
- except UnknownFileTypeError:
135
- console.print(f"[red]Error: Unknown file type for input file '{input_file}'[/red]")
136
- console.print(f"[yellow]The file extension '{input_ext}' is not recognized.[/yellow]")
137
- console.print("[yellow]Make sure the file has the correct extension for its format.[/yellow]")
138
- return
139
- except Exception as e:
140
- console.print(f"[red]Error reading input file '{input_file}': {str(e)}.[/red]")
141
- console.print(f"[yellow]Make sure '{input_ext}' is a valid format and the file is not corrupted.[/yellow]")
142
- return
143
-
144
- try:
145
- if output_ext == "atraj":
146
- write_atraj(atoms, output_file)
147
- elif output_ext == "tess":
148
- write_tess(atoms, output_file)
149
- else:
150
- write(output_file, atoms)
151
-
152
- console.print(f"[green]Successfully converted {input_file} to {output_file}[/green]")
153
-
154
- except UnknownFileTypeError:
155
- console.print(f"[red]Error: Unknown file type for output file '{output_file}'[/red]")
156
- console.print(f"[yellow]The file extension '{output_ext}' is not recognized.[/yellow]")
157
- console.print("[yellow]Make sure the file has the correct extension for its format.[/yellow]")
158
- return
159
- except Exception as e:
160
- console.print(f"[red]Error writing output file '{output_file}': {str(e)}[/red]")
161
- console.print(f"[yellow]Make sure '{output_ext}' is a valid format and you have write permissions.[/yellow]")
162
- return
163
-
164
- except Exception as e:
165
- logging.debug(f"Conversion failed with error: {str(e)}", exc_info=True)
166
- console.print(f"[red]Error during conversion: {str(e)}[/red]")
167
- console.print("[yellow]Try running with --verbose for more detailed error information.[/yellow]")
168
-
169
-
170
53
  @cli.command(hidden=True)
171
54
  @click.argument("shell", type=click.Choice(["bash", "zsh", "fish"]), required=False)
172
55
  def completion(shell):
@@ -207,21 +90,19 @@ end
207
90
 
208
91
 
209
92
  cli.add_command(completion)
93
+ cli.add_command(convert.convert)
210
94
  cli.add_command(task.task_group)
211
95
  cli.add_command(upload.upload_group)
212
96
  cli.add_command(project.project_group)
213
97
  cli.add_command(k8s.k8s_group)
214
- cli.add_command(adsorbate.adsorbate_group)
215
98
  cli.add_command(fhiaims.fhiaims_group)
216
99
  cli.add_command(kpoint.kpoint_group)
217
- cli.add_command(catalysis.catalysis_group)
218
100
  cli.add_command(sqs.sqs_group)
219
101
  cli.add_command(soec.soecexploration_group)
220
102
  cli.add_command(traj.traj)
221
103
  cli.add_command(user.user_group)
222
104
  cli.add_command(login._login)
223
105
  cli.add_command(token._token)
224
- cli.add_command(vibes.vibes_group)
225
106
 
226
107
 
227
108
  def main():
atomict/io/cif.py CHANGED
@@ -1,14 +1,8 @@
1
1
  import logging
2
- try:
3
- import ase.io
4
- import spglib
5
- from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
6
- from pymatgen.core import Structure
7
- except ImportError:
8
- raise ImportError(
9
- "The 'ase' package is required for FHI-aims operations. "
10
- "To install the optional dependencies such as ase, spglib, pymatgen, use `pip install atomict[utils]`"
11
- )
2
+ import ase.io
3
+ import spglib
4
+ from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
5
+ from pymatgen.core import Structure
12
6
 
13
7
 
14
8
  class CIFAnalyzer:
atomict/io/fhiaims.py CHANGED
@@ -1,11 +1,5 @@
1
- try:
2
- from ase.io.aims import check_convergence, get_aims_out_chunks, get_header_chunk
3
- from ase.utils import reader
4
- except ImportError:
5
- raise ImportError(
6
- "The 'ase' package is required for FHI-aims operations. "
7
- "To install the optional dependencies such as ase, spglib, pymatgen, use `pip install atomict[utils]`"
8
- )
1
+ from ase.io.aims import check_convergence, get_aims_out_chunks, get_header_chunk
2
+ from ase.utils import reader
9
3
 
10
4
 
11
5
  # We have to write our own function because he read_aims_output function inside ASE only supports
@@ -9,13 +9,9 @@ def write_atraj(atoms: Union['ase.Atoms', List['ase.Atoms']], filename: str, met
9
9
  """Save atoms to a mpv1 file."""
10
10
 
11
11
  from atomict.io.atoms import atoms_to_dict
12
-
13
- try:
14
- import msgpack
15
- import msgpack_numpy as m
16
- from ase import Atoms
17
- except ImportError:
18
- raise ImportError("You need to install with `pip install atomict[utils]` to use the newer formats")
12
+ import msgpack
13
+ import msgpack_numpy as m
14
+ from ase import Atoms
19
15
 
20
16
  # Enable numpy array serialization
21
17
  m.patch()
@@ -47,12 +43,8 @@ def read_atraj(filename: str) -> Union['ase.Atoms', List['ase.Atoms']]:
47
43
 
48
44
  """Load atoms from a mpv1 file."""
49
45
  from atomict.io.atoms import dict_to_atoms
50
-
51
- try:
52
- import msgpack
53
- import msgpack_numpy as m
54
- except ImportError:
55
- raise ImportError("You need to install with `pip install atomict[utils]` to use the newer formats")
46
+ import msgpack
47
+ import msgpack_numpy as m
56
48
 
57
49
  # Enable numpy array deserialization
58
50
  m.patch()