atomict 1.2.22__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.
@@ -1,223 +0,0 @@
1
- # cli/commands/simulation/catalysis.py
2
- from typing import Any, Dict, Optional
3
-
4
- import click
5
- from rich.console import Console
6
- from rich.panel import Panel
7
- from rich.table import Table
8
-
9
- from atomict.cli.commands.helpers import (
10
- create_detail_table,
11
- format_datetime,
12
- format_task_status,
13
- )
14
- from atomict.cli.core.client import get_client
15
-
16
- console = Console()
17
-
18
-
19
- @click.group(name="catalysis")
20
- def catalysis_group():
21
- """Manage catalysis simulations"""
22
- pass
23
-
24
-
25
- def format_catalysis_table(simulations: list[Dict[str, Any]]) -> Table:
26
- """Create a table with catalysis simulation fields"""
27
- table = Table(show_header=True)
28
-
29
- columns = {
30
- "ID": lambda x: str(x["id"]),
31
- "Name": lambda x: x.get("name", "N/A"),
32
- "Status": lambda x: x.get("task", {}).get("status", "N/A"),
33
- "Progress": lambda x: f"{x.get('task', {}).get('progress', 0)}%",
34
- "Results": lambda x: x.get("num_results", "0"),
35
- "Created": lambda x: format_datetime(x.get("created_at", "")),
36
- }
37
-
38
- for col_name in columns:
39
- table.add_column(col_name)
40
-
41
- for sim in simulations:
42
- row = [columns[col_name](sim) for col_name in columns]
43
- table.add_row(*row)
44
-
45
- return table
46
-
47
-
48
- def format_catalysis_detail(sim: Dict[str, Any]) -> None:
49
- """Display detailed catalysis simulation information"""
50
- # Main info panel
51
- console.print(Panel(f"[bold]{sim.get('name', 'Unnamed Simulation')}[/bold]"))
52
-
53
- # Basic info
54
- basic_fields = {
55
- "ID": "id",
56
- "Name": "name",
57
- "Created": "created_at",
58
- "Edited": "edited_at",
59
- "Bulk ID": "bulk_id",
60
- "Slab ID": "slab_id",
61
- "Calculator": "calculator_class",
62
- "Max Force": "fmax",
63
- "Steps": "steps",
64
- }
65
- console.print(create_detail_table("Basic Information", sim, basic_fields))
66
-
67
- # Task status
68
- if task_table := format_task_status(sim.get("task")):
69
- console.print(task_table)
70
-
71
- # Results summary
72
- results_fields = {
73
- "Total Results": "num_results",
74
- "Dissociated": "num_results_dissociated",
75
- "Desorbed": "num_results_desorbed",
76
- "Surface Changed": "num_results_surface_changed",
77
- "Intercalated": "num_results_intercalated",
78
- }
79
- console.print(create_detail_table("Results Summary", sim, results_fields))
80
-
81
-
82
- def format_results_detail(results: Dict[str, Any]) -> None:
83
- """Display detailed simulation results"""
84
- # Energy and convergence info
85
- energy_table = Table(show_header=True, title="Energy Results")
86
- energy_table.add_column("Property")
87
- energy_table.add_column("Value")
88
-
89
- energy_fields = {
90
- "Total Energy": "energy",
91
- "ML Energy": "ml_energy",
92
- "Min ML Energy": "min_ml_energy",
93
- "Converged": lambda r: "✓" if r.get("converged") else "✗",
94
- "Force Calls": "force_calls",
95
- }
96
-
97
- for label, field in energy_fields.items():
98
- if callable(field):
99
- value = field(results)
100
- else:
101
- value = results.get(field, "N/A")
102
- energy_table.add_row(label, str(value))
103
-
104
- console.print(energy_table)
105
-
106
- # Structure information
107
- if structure := results.get("final_structure"):
108
- structure_table = Table(show_header=True, title="Final Structure")
109
- structure_table.add_column("Property")
110
- structure_table.add_column("Value")
111
-
112
- structure_fields = {
113
- "Atoms": "num_atoms",
114
- "Cell": "cell",
115
- "Positions": "positions",
116
- "Forces": "forces",
117
- }
118
-
119
- for label, field in structure_fields.items():
120
- value = structure.get(field, "N/A")
121
- structure_table.add_row(label, str(value))
122
-
123
- console.print(structure_table)
124
-
125
-
126
- @catalysis_group.command()
127
- @click.argument("id", required=False)
128
- @click.option("--json-output", is_flag=True, help="Output in JSON format")
129
- def get(id: Optional[str] = None, json_output: bool = False):
130
- """Get catalysis simulation details or list all"""
131
- # TODO: support more options, filtering, and search
132
- client = get_client()
133
-
134
- if id:
135
- result = client.get(f"/api/catalysis-simulation/{id}/")
136
- if json_output:
137
- console.print_json(data=result)
138
- return
139
- format_catalysis_detail(result)
140
- else:
141
- results = client.get_all("/api/catalysis-simulation/")
142
- if json_output:
143
- console.print_json(data=results)
144
- return
145
-
146
- # Add pagination info
147
- if isinstance(results, dict):
148
- items = results.get("results", [])
149
- count = results.get("count")
150
- page_size = len(items)
151
- if count and page_size:
152
- console.print(f"\nShowing page 1 of {(count - 1) // page_size + 1}")
153
- console.print(f"Total items: {count}")
154
- if results.get("next"):
155
- console.print("Use --all to fetch all results")
156
- else:
157
- items = results
158
-
159
- console.print(format_catalysis_table(items)) # Make sure we print the table
160
-
161
-
162
- @catalysis_group.group(name="results")
163
- def results_group():
164
- """Manage catalysis simulation results"""
165
- pass
166
-
167
-
168
- @results_group.command(name="get")
169
- @click.argument("id", required=False)
170
- @click.option("--json-output", is_flag=True, help="Output in JSON format")
171
- @click.option("--simulation-id", help="Filter by simulation ID")
172
- @click.option("--converged", type=bool, help="Filter by convergence status")
173
- def results_get(
174
- id: Optional[str] = None,
175
- json_output: bool = False,
176
- simulation_id: Optional[str] = None,
177
- converged: Optional[bool] = None,
178
- ):
179
- """Get simulation results details or list all results"""
180
- client = get_client()
181
-
182
- params = {}
183
- if simulation_id:
184
- params["simulation"] = simulation_id
185
- if converged is not None:
186
- params["converged"] = converged
187
-
188
- if id:
189
- result = client.get(f"/api/catalysis-simulation-results/{id}/")
190
- if json_output:
191
- console.print_json(data=result)
192
- return
193
- format_results_detail(result)
194
- else:
195
- results = client.get_all("/api/catalysis-simulation-results/", params)
196
- if json_output:
197
- console.print_json(data=results)
198
- return
199
-
200
- table = Table(show_header=True)
201
- table.add_column("ID")
202
- table.add_column("Simulation")
203
- table.add_column("Energy")
204
- table.add_column("ML Energy")
205
- table.add_column("Converged")
206
- table.add_column("Created")
207
-
208
- for res in results:
209
- table.add_row(
210
- str(res["id"]),
211
- str(res.get("simulation", "N/A")),
212
- str(res.get("energy", "N/A")),
213
- str(res.get("ml_energy", "N/A")),
214
- "✓" if res.get("converged") else "✗",
215
- format_datetime(res.get("created_at", "")),
216
- )
217
- console.print(table)
218
-
219
-
220
- # Add results group to catalysis group
221
- catalysis_group.add_command(results_group)
222
-
223
- catalysis = catalysis_group
@@ -1,161 +0,0 @@
1
- from typing import Optional
2
-
3
- import click
4
- from rich.console import Console
5
-
6
- from atomict.cli.commands.common import create_table
7
- from atomict.cli.commands.helpers import format_datetime, get_status_string
8
- from atomict.cli.core.client import get_client
9
- from atomict.cli.core.utils import get_pagination_info
10
-
11
- console = Console()
12
-
13
-
14
- @click.group(name="vibes")
15
- def vibes_group():
16
- """Manage VIBES simulations"""
17
- pass
18
-
19
-
20
- @vibes_group.command()
21
- @click.argument("id", required=False)
22
- @click.option("--search", help="Search term")
23
- @click.option("--ordering", help="Field to order results by")
24
- @click.option("--filter", "filters", multiple=True, help="Filter in format field=value")
25
- @click.option("--json-output", is_flag=True, help="Output in JSON format")
26
- @click.option("--all", "fetch_all", is_flag=True, help="Fetch all results")
27
- def get(
28
- id: Optional[str] = None,
29
- search: Optional[str] = None,
30
- ordering: Optional[str] = None,
31
- filters: tuple = (),
32
- json_output: bool = False,
33
- fetch_all: bool = False,
34
- ):
35
- """Get simulation details or list all simulations"""
36
- client = get_client()
37
-
38
- if id:
39
- simulation = client.get(f"/api/vibes-simulation/{id}/")
40
- if json_output:
41
- console.print_json(data=simulation)
42
- return
43
- # Format single simulation output
44
- console.print(f"ID: {simulation['id']}")
45
- console.print(f"Name: {simulation.get('name', 'N/A')}")
46
- console.print(f"Created: {format_datetime(simulation['created_at'])}")
47
- console.print(f"Updated: {format_datetime(simulation['updated_at'])}")
48
- console.print(f"Calculator Parameters: {simulation.get('calculator_parameters', {})}")
49
- console.print(f"Calculator K-points: {simulation.get('calculator_kpoints', {})}")
50
- console.print(f"Calculator Basis Set: {simulation.get('calculator_basis_set', {})}")
51
- if simulation.get("task"):
52
- status = get_status_string(simulation["task"].get("status"))
53
- console.print(f"Status: {status}")
54
- if simulation.get("starting_structure"):
55
- console.print(f"Starting Structure ID: {simulation['starting_structure']['id']}")
56
- else:
57
- params = {}
58
- if search:
59
- params["search"] = search
60
- if ordering:
61
- params["ordering"] = ordering
62
-
63
- for f in filters:
64
- try:
65
- field, value = f.split("=", 1)
66
- params[field] = value
67
- except ValueError:
68
- click.echo(f"Invalid filter format: {f}. Use field=value", err=True)
69
- return
70
-
71
- if fetch_all:
72
- results = client.get_all("/api/vibes-simulation/", params=params)
73
- else:
74
- results = client.get("/api/vibes-simulation/", params=params)
75
-
76
- if json_output:
77
- console.print_json(data=results)
78
- return
79
-
80
- columns = [
81
- ("ID", "id", None),
82
- ("Name", "name", None),
83
- ("Status", "task", lambda x: get_status_string(x.get("status") if isinstance(x, dict) else None)),
84
- ("Created", "created_at", format_datetime),
85
- ("Updated", "updated_at", format_datetime),
86
- ("Starting Structure", "starting_structure", lambda x: x.get("id") if isinstance(x, dict) else None),
87
- ]
88
-
89
- items, footer_string = get_pagination_info(results)
90
-
91
- if not items:
92
- console.print(
93
- f"[white]No simulations found with the given criteria:[/white]\n[green]{params}"
94
- )
95
- return
96
-
97
- table = create_table(
98
- columns=columns,
99
- items=items,
100
- title="VIBES Simulations",
101
- caption=footer_string,
102
- )
103
-
104
- console.print(table)
105
-
106
-
107
- @vibes_group.command()
108
- @click.option("--name", help="Simulation name")
109
- @click.option("--description", help="Simulation description")
110
- @click.option("--starting-structure-id", help="ID of the starting FHI-aims structure")
111
- @click.option(
112
- "--xc",
113
- type=str,
114
- help="Phonopy.in setting: Exchange-correlation functional (e.g. 'pw-lda')",
115
- )
116
- @click.option(
117
- "--kpoint-density",
118
- type=float,
119
- help="Phonopy.in setting: K-point density (e.g. 3.5)",
120
- )
121
- @click.option(
122
- "--basis-set",
123
- type=str,
124
- help="Phonopy.in setting: Basis set (e.g. 'light')",
125
- )
126
- def create(
127
- name: Optional[str],
128
- description: Optional[str],
129
- starting_structure_id: Optional[str],
130
- xc: Optional[str],
131
- kpoint_density: Optional[float],
132
- basis_set: Optional[str],
133
- ):
134
- """Create a new VIBES simulation"""
135
- client = get_client()
136
- data = {}
137
-
138
- if name:
139
- data["name"] = name
140
- if description:
141
- data["description"] = description
142
- if starting_structure_id:
143
- data["starting_structure"] = starting_structure_id
144
- if xc:
145
- data["calculator_parameters"] = {"xc": xc}
146
- if kpoint_density:
147
- data["calculator_kpoints"] = {"density": kpoint_density}
148
- if basis_set:
149
- data["calculator_basis_set"] = {"default": basis_set}
150
-
151
- simulation = client.post("/api/vibes-simulation/", data=data)
152
- console.print(f"[green]Created simulation with ID: {simulation['id']}[/green]")
153
-
154
-
155
- @vibes_group.command()
156
- @click.argument("id")
157
- def delete(id: str):
158
- """Delete a VIBES simulation"""
159
- client = get_client()
160
- client.delete(f"/api/vibes-simulation/{id}/")
161
- console.print(f"[green]Deleted simulation {id}[/green]")
@@ -1,176 +0,0 @@
1
- # cli/commands/simulation.py
2
- import logging
3
- from typing import Any, Dict, Optional
4
-
5
- import click
6
- from rich.console import Console
7
- from rich.panel import Panel
8
- from rich.progress import Progress
9
- from rich.table import Table
10
-
11
- console = Console()
12
- logger = logging.getLogger(__name__)
13
-
14
-
15
- @click.group(name="simulation")
16
- def simulation():
17
- """Manage simulations"""
18
- pass
19
-
20
-
21
- def format_simulation_table(simulations: list[Dict[str, Any]]) -> Table:
22
- """Create a table with the most relevant simulation fields"""
23
- table = Table(show_header=True)
24
-
25
- # Key fields we want to show in the list view
26
- columns = {
27
- "ID": lambda x: str(x["id"]),
28
- "Name": lambda x: x.get("name", "N/A"),
29
- "Status": lambda x: x.get("task", {}).get("status", "N/A"),
30
- "Progress": lambda x: f"{x.get('task', {}).get('progress', 0)}%",
31
- "Results": lambda x: x.get("num_results", "0"),
32
- "Created": lambda x: x.get("created_at", "N/A"),
33
- }
34
-
35
- # Add columns
36
- for col_name in columns:
37
- table.add_column(col_name)
38
-
39
- # Add rows
40
- for sim in simulations:
41
- row = [columns[col_name](sim) for col_name in columns]
42
- table.add_row(*row)
43
-
44
- return table
45
-
46
-
47
- def format_simulation_detail(sim: Dict[str, Any]) -> None:
48
- """Display detailed simulation information"""
49
- # Main info panel
50
- console.print(Panel(f"[bold]{sim.get('name', 'Unnamed Simulation')}[/bold]"))
51
-
52
- # Basic info table
53
- basic_info = Table(show_header=True, title="Basic Information")
54
- basic_info.add_column("Property")
55
- basic_info.add_column("Value")
56
-
57
- basic_fields = {
58
- "ID": "id",
59
- "Name": "name",
60
- "Created": "created_at",
61
- "Edited": "edited_at",
62
- "Bulk ID": "bulk_id",
63
- "Slab ID": "slab_id",
64
- "Calculator": "calculator_class",
65
- "Max Force": "fmax",
66
- "Steps": "steps",
67
- }
68
-
69
- for label, field in basic_fields.items():
70
- value = sim.get(field, "N/A")
71
- basic_info.add_row(label, str(value))
72
-
73
- console.print(basic_info)
74
- console.print()
75
-
76
- # Task status if present
77
- if task := sim.get("task"):
78
- task_info = Table(show_header=True, title="Task Status")
79
- task_info.add_column("Property")
80
- task_info.add_column("Value")
81
-
82
- task_fields = {
83
- "Status": "status",
84
- "Progress": "progress",
85
- "Running On": "running_on",
86
- "Error": "error",
87
- }
88
-
89
- for label, field in task_fields.items():
90
- value = task.get(field, "N/A")
91
- task_info.add_row(label, str(value))
92
-
93
- console.print(task_info)
94
- console.print()
95
-
96
- # Results summary if present
97
- results = Table(show_header=True, title="Results Summary")
98
- results.add_column("Metric")
99
- results.add_column("Count")
100
-
101
- result_fields = {
102
- "Total Results": "num_results",
103
- "Dissociated": "num_results_dissociated",
104
- "Desorbed": "num_results_desorbed",
105
- "Surface Changed": "num_results_surface_changed",
106
- "Intercalated": "num_results_intercalated",
107
- }
108
-
109
- for label, field in result_fields.items():
110
- value = sim.get(field, "0")
111
- results.add_row(label, str(value))
112
-
113
- console.print(results)
114
-
115
-
116
- @simulation.command()
117
- @click.argument("id", required=False)
118
- @click.option("--json-output", is_flag=True, help="Output in JSON format")
119
- def get(id: Optional[str] = None, json_output: bool = False):
120
- """Get simulation details or list all simulations"""
121
- from atomict.cli.core.client import get_client
122
-
123
- client = get_client()
124
-
125
- if id:
126
- result = client.get(f"/api/catalysis-simulation/{id}/")
127
- if json_output:
128
- console.print_json(data=result)
129
- return
130
-
131
- format_simulation_detail(result)
132
- else:
133
- results = client.get_all("/api/catalysis-simulation/")
134
- if json_output:
135
- console.print_json(data=results)
136
- return
137
-
138
- console.print(format_simulation_table(results))
139
-
140
-
141
- @simulation.command()
142
- @click.argument("id")
143
- @click.option("--output", "-o", help="Output file path")
144
- def download_results(id: str, output: Optional[str]):
145
- """Download simulation results file"""
146
- from pathlib import Path
147
-
148
- from atomict.cli.core.client import get_client
149
-
150
- client = get_client()
151
-
152
- with console.status("[bold green]Downloading simulation results..."):
153
- response = client.get(f"/api/catalysis-simulation-results/{id}/download/")
154
-
155
- # Get filename from response headers or use provided output path
156
- if output:
157
- filename = Path(output)
158
- else:
159
- content_disposition = response.headers.get("content-disposition", "")
160
- filename = (
161
- Path(content_disposition.split("filename=")[-1].strip('"'))
162
- if content_disposition
163
- else Path(f"simulation_{id}_results.dat")
164
- )
165
-
166
- total_size = int(response.headers.get("content-length", 0))
167
-
168
- with open(filename, "wb") as f:
169
- with Progress() as progress:
170
- task = progress.add_task("[cyan]Downloading...", total=total_size)
171
-
172
- for chunk in response.iter_bytes(chunk_size=8192):
173
- f.write(chunk)
174
- progress.update(task, advance=len(chunk))
175
-
176
- console.print(f"[green]Results downloaded to: {filename}[/green]")
@@ -1,46 +0,0 @@
1
- import click
2
- from rich.console import Console
3
-
4
-
5
- class DefaultCommandGroup(click.Group):
6
- """Allow a default command for a group.
7
-
8
- This class extends Click's Group to support a default command that gets executed
9
- when no subcommand is specified or when arguments don't match any known command.
10
- """
11
-
12
- def command(self, *args, **kwargs):
13
- default_command = kwargs.pop('default_command', False)
14
- if default_command and not args:
15
- kwargs['name'] = kwargs.get('name', ' ')
16
- decorator = super(DefaultCommandGroup, self).command(*args, **kwargs)
17
-
18
- if default_command:
19
- def new_decorator(f):
20
- cmd = decorator(f)
21
- self.default_command = cmd.name
22
- return cmd
23
-
24
- return new_decorator
25
-
26
- return decorator
27
-
28
- def resolve_command(self, ctx, args):
29
- try:
30
- # test if the command parses
31
- return super(DefaultCommandGroup, self).resolve_command(ctx, args)
32
- except click.UsageError:
33
- # command did not parse, assume it is the default command
34
- args.insert(0, self.default_command)
35
- return super(DefaultCommandGroup, self).resolve_command(ctx, args)
36
-
37
- def get_help(self, ctx):
38
- """Override help formatting to add additional resources section."""
39
- help_text = super().get_help(ctx)
40
-
41
- # Add additional resources section with extra spacing
42
- additional_resources = "\n\nAdditional Resources:\n"
43
- additional_resources += " To get help join the Atomic Tessellator discord community at this link:\n"
44
- additional_resources += " https://discord.com/invite/atomictessellator\n"
45
-
46
- return help_text + additional_resources
@@ -1,20 +0,0 @@
1
- from atomict.api import get, post
2
-
3
-
4
- def get_exploration(exploration_id: str):
5
- return get(f"api/catalysis-exploration/{exploration_id}/")
6
-
7
-
8
- def get_simulation(simulation_id: str):
9
- return get(f"api/catalysis-simulation/{simulation_id}/")
10
-
11
-
12
- def upload_simulation_results(results, traj_file_path, log_file_path):
13
- url = "simulation/catalysis/mlacc/results_upload/"
14
-
15
- files = {
16
- "traj": ("simulation.traj", open(traj_file_path, "rb")),
17
- "logs": ("simulation.log", open(log_file_path, "rb")),
18
- }
19
-
20
- return post(url, results, files=files)