rowan-python 0.0.1__tar.gz → 0.0.3__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.
- rowan-python-0.0.3/LICENSE +21 -0
- rowan-python-0.0.3/PKG-INFO +32 -0
- rowan-python-0.0.3/README.md +17 -0
- {rowan-python-0.0.1 → rowan-python-0.0.3}/pyproject.toml +2 -2
- rowan-python-0.0.3/rowan/client.py +152 -0
- rowan-python-0.0.3/rowan/utils.py +33 -0
- rowan-python-0.0.3/rowan_python.egg-info/PKG-INFO +32 -0
- {rowan-python-0.0.1 → rowan-python-0.0.3}/rowan_python.egg-info/SOURCES.txt +1 -0
- {rowan-python-0.0.1 → rowan-python-0.0.3}/rowan_python.egg-info/requires.txt +1 -1
- rowan-python-0.0.1/PKG-INFO +0 -78
- rowan-python-0.0.1/README.md +0 -64
- rowan-python-0.0.1/rowan/client.py +0 -107
- rowan-python-0.0.1/rowan/utils.py +0 -15
- rowan-python-0.0.1/rowan_python.egg-info/PKG-INFO +0 -78
- {rowan-python-0.0.1 → rowan-python-0.0.3}/rowan/__init__.py +0 -0
- {rowan-python-0.0.1 → rowan-python-0.0.3}/rowan_python.egg-info/dependency_links.txt +0 -0
- {rowan-python-0.0.1 → rowan-python-0.0.3}/rowan_python.egg-info/top_level.txt +0 -0
- {rowan-python-0.0.1 → rowan-python-0.0.3}/setup.cfg +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Rowan (https://rowansci.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: rowan-python
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Rowan Python Library
|
|
5
|
+
Author-email: Corin Wagen <corin@rowansci.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/rowansci/rowan-client
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/rowansci/rowan-client/issues
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: cctk>=0.2.18
|
|
12
|
+
Requires-Dist: httpx>=0.25
|
|
13
|
+
Requires-Dist: numpy>=1.24
|
|
14
|
+
Requires-Dist: stjames>=0.0.23
|
|
15
|
+
|
|
16
|
+
# Rowan Python Library
|
|
17
|
+
|
|
18
|
+
[](https://pypi.python.org/pypi/rowan-python)
|
|
19
|
+
[](https://github.com/charliermarsh/ruff)
|
|
20
|
+
|
|
21
|
+
The Rowan Python library provides convenient access to the Rowan API from applications written in the Python language.
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
The documentation is available [here](https://docs.rowansci.com/python-api).
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## Issues
|
|
29
|
+
|
|
30
|
+
To report issues, please use the "Issues" tab above.
|
|
31
|
+
|
|
32
|
+
*Corin Wagen, 2023*
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Rowan Python Library
|
|
2
|
+
|
|
3
|
+
[](https://pypi.python.org/pypi/rowan-python)
|
|
4
|
+
[](https://github.com/charliermarsh/ruff)
|
|
5
|
+
|
|
6
|
+
The Rowan Python library provides convenient access to the Rowan API from applications written in the Python language.
|
|
7
|
+
|
|
8
|
+
## Documentation
|
|
9
|
+
|
|
10
|
+
The documentation is available [here](https://docs.rowansci.com/python-api).
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Issues
|
|
14
|
+
|
|
15
|
+
To report issues, please use the "Issues" tab above.
|
|
16
|
+
|
|
17
|
+
*Corin Wagen, 2023*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "rowan-python"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.3"
|
|
4
4
|
description = "Rowan Python Library"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.8"
|
|
@@ -12,7 +12,7 @@ dependencies = [
|
|
|
12
12
|
"cctk>=0.2.18",
|
|
13
13
|
"httpx>=0.25",
|
|
14
14
|
"numpy>=1.24",
|
|
15
|
-
"stjames>=0.0.
|
|
15
|
+
"stjames>=0.0.23",
|
|
16
16
|
]
|
|
17
17
|
|
|
18
18
|
[build-system]
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import cctk
|
|
4
|
+
import httpx
|
|
5
|
+
from typing import Optional
|
|
6
|
+
import stjames
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
import time
|
|
9
|
+
|
|
10
|
+
import rowan
|
|
11
|
+
|
|
12
|
+
API_URL = "https://api.rowansci.com"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class Client:
|
|
17
|
+
blocking: bool = True
|
|
18
|
+
print: bool = True
|
|
19
|
+
ping_interval: int = 5
|
|
20
|
+
delete_when_finished: bool = False
|
|
21
|
+
|
|
22
|
+
headers: dict = field(init=False)
|
|
23
|
+
|
|
24
|
+
def __post_init__(self):
|
|
25
|
+
self.headers = {"X-API-Key": rowan.utils.get_api_key()}
|
|
26
|
+
|
|
27
|
+
if not self.blocking and self.delete_when_finished:
|
|
28
|
+
print("Warning: ``delete_when_finished`` has no effect when ``blocking`` is False. To delete calculations, call ``Client.delete()`` manually.")
|
|
29
|
+
|
|
30
|
+
def compute(
|
|
31
|
+
self,
|
|
32
|
+
type: Optional[str] = "calculation",
|
|
33
|
+
input_mol: Optional[cctk.Molecule] = None,
|
|
34
|
+
input_smiles: Optional[str] = None,
|
|
35
|
+
name: Optional[str] = None,
|
|
36
|
+
folder_uuid: Optional[str] = None,
|
|
37
|
+
engine: str = "peregrine",
|
|
38
|
+
**options,
|
|
39
|
+
) -> dict | str:
|
|
40
|
+
if (input_mol is None) == (input_smiles is None):
|
|
41
|
+
raise ValueError("Must specify exactly one of ``input_smiles`` and ``input_mol``!")
|
|
42
|
+
|
|
43
|
+
if input_mol is None:
|
|
44
|
+
input_mol = cctk.Molecule.new_from_smiles(input_smiles)
|
|
45
|
+
|
|
46
|
+
molecule = rowan.utils.cctk_to_stjames(input_mol)
|
|
47
|
+
|
|
48
|
+
with httpx.Client() as client:
|
|
49
|
+
if type == "calculation":
|
|
50
|
+
settings = stjames.Settings(**options)
|
|
51
|
+
calc = stjames.Calculation(molecules=[molecule], name=name, engine=engine, settings=settings)
|
|
52
|
+
|
|
53
|
+
response = client.post(
|
|
54
|
+
f"{API_URL}/calculation",
|
|
55
|
+
headers=self.headers,
|
|
56
|
+
json={
|
|
57
|
+
"json_data": calc.model_dump(mode="json"),
|
|
58
|
+
"folder_uuid": folder_uuid,
|
|
59
|
+
},
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
elif type in ["pka", "conformers", "tautomers"]:
|
|
63
|
+
response = client.post(
|
|
64
|
+
f"{API_URL}/workflow",
|
|
65
|
+
headers=self.headers,
|
|
66
|
+
json={
|
|
67
|
+
"initial_molecule": molecule.model_dump(mode="json"),
|
|
68
|
+
"workflow_type": type,
|
|
69
|
+
"name": name,
|
|
70
|
+
"folder_uuid": folder_uuid,
|
|
71
|
+
"workflow_data": options,
|
|
72
|
+
},
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
response.raise_for_status()
|
|
76
|
+
response_dict = response.json()
|
|
77
|
+
calc_uuid = response_dict["uuid"]
|
|
78
|
+
|
|
79
|
+
if self.blocking:
|
|
80
|
+
while not self.is_finished(calc_uuid, type):
|
|
81
|
+
time.sleep(self.ping_interval)
|
|
82
|
+
result = self.get(calc_uuid, type)
|
|
83
|
+
|
|
84
|
+
if self.delete_when_finished:
|
|
85
|
+
self.delete(calc_uuid, type)
|
|
86
|
+
|
|
87
|
+
return result
|
|
88
|
+
|
|
89
|
+
else:
|
|
90
|
+
return calc_uuid
|
|
91
|
+
|
|
92
|
+
def is_finished(self, calc_uuid: str, type: str = "calculation") -> bool:
|
|
93
|
+
with httpx.Client() as client:
|
|
94
|
+
if type == "calculation":
|
|
95
|
+
response = client.get(f"{API_URL}/calculation/{calc_uuid}", headers=self.headers)
|
|
96
|
+
response.raise_for_status()
|
|
97
|
+
response_dict = response.json()
|
|
98
|
+
status = response_dict["status"]
|
|
99
|
+
|
|
100
|
+
elif type in ["pka", "conformers", "tautomers"]:
|
|
101
|
+
response = client.get(f"{API_URL}/workflow/{calc_uuid}", headers=self.headers)
|
|
102
|
+
response.raise_for_status()
|
|
103
|
+
response_dict = response.json()
|
|
104
|
+
status = response_dict["object_status"]
|
|
105
|
+
|
|
106
|
+
else:
|
|
107
|
+
raise ValueError(f"Unknown type ``{type}``!")
|
|
108
|
+
|
|
109
|
+
return status in [2, 3, 4]
|
|
110
|
+
|
|
111
|
+
def get(self, calc_uuid: str, type: str = "calculation") -> dict:
|
|
112
|
+
with httpx.Client() as client:
|
|
113
|
+
if type == "calculation":
|
|
114
|
+
response = client.get(f"{API_URL}/calculation/{calc_uuid}/stjames", headers=self.headers)
|
|
115
|
+
response.raise_for_status()
|
|
116
|
+
response_dict = response.json()
|
|
117
|
+
return response_dict
|
|
118
|
+
|
|
119
|
+
elif type in ["pka", "conformers", "tautomers"]:
|
|
120
|
+
response = client.get(f"{API_URL}/workflow/{calc_uuid}", headers=self.headers)
|
|
121
|
+
response.raise_for_status()
|
|
122
|
+
response_dict = response.json()
|
|
123
|
+
return response_dict["object_data"]
|
|
124
|
+
|
|
125
|
+
else:
|
|
126
|
+
raise ValueError(f"Unknown type ``{type}``!")
|
|
127
|
+
|
|
128
|
+
def stop(self, calc_uuid: str, type: str = "calculation") -> None:
|
|
129
|
+
with httpx.Client() as client:
|
|
130
|
+
if type == "calculation":
|
|
131
|
+
response = client.post(f"{API_URL}/calculation/{calc_uuid}/stop", headers=self.headers)
|
|
132
|
+
response.raise_for_status()
|
|
133
|
+
|
|
134
|
+
elif type in ["pka", "conformers", "tautomers"]:
|
|
135
|
+
response = client.post(f"{API_URL}/workflow/{calc_uuid}/stop", headers=self.headers)
|
|
136
|
+
response.raise_for_status()
|
|
137
|
+
|
|
138
|
+
else:
|
|
139
|
+
raise ValueError(f"Unknown type ``{type}``!")
|
|
140
|
+
|
|
141
|
+
def delete(self, calc_uuid: str, type: str = "calculation") -> None:
|
|
142
|
+
with httpx.Client() as client:
|
|
143
|
+
if type == "calculation":
|
|
144
|
+
response = client.delete(f"{API_URL}/calculation/{calc_uuid}", headers=self.headers)
|
|
145
|
+
response.raise_for_status()
|
|
146
|
+
|
|
147
|
+
elif type in ["pka", "conformers", "tautomers"]:
|
|
148
|
+
response = client.delete(f"{API_URL}/folder/{calc_uuid}", headers=self.headers)
|
|
149
|
+
response.raise_for_status()
|
|
150
|
+
|
|
151
|
+
else:
|
|
152
|
+
raise ValueError(f"Unknown type ``{type}``!")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import cctk
|
|
3
|
+
import stjames
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
import rowan
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_api_key() -> str:
|
|
10
|
+
api_key = os.environ.get("ROWAN_API_KEY")
|
|
11
|
+
if api_key is not None:
|
|
12
|
+
return api_key
|
|
13
|
+
elif hasattr(rowan, "api_key"):
|
|
14
|
+
return rowan.api_key
|
|
15
|
+
else:
|
|
16
|
+
raise ValueError(
|
|
17
|
+
"No API key provided. You can set your API key using 'rowan.api_key = <API-KEY>', or you can set the environment variable ROWAN_API_KEY=<API-KEY>)."
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def cctk_to_stjames(molecule: cctk.Molecule) -> stjames.Molecule:
|
|
22
|
+
atomic_numbers = molecule.atomic_numbers.view(np.ndarray)
|
|
23
|
+
geometry = molecule.geometry.view(np.ndarray)
|
|
24
|
+
|
|
25
|
+
atoms = list()
|
|
26
|
+
for i in range(molecule.num_atoms()):
|
|
27
|
+
atoms.append(stjames.Atom(atomic_number=atomic_numbers[i], position=geometry[i]))
|
|
28
|
+
|
|
29
|
+
return stjames.Molecule(
|
|
30
|
+
atoms=atoms,
|
|
31
|
+
charge=molecule.charge,
|
|
32
|
+
multiplicity=molecule.multiplicity,
|
|
33
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: rowan-python
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Rowan Python Library
|
|
5
|
+
Author-email: Corin Wagen <corin@rowansci.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/rowansci/rowan-client
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/rowansci/rowan-client/issues
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: cctk>=0.2.18
|
|
12
|
+
Requires-Dist: httpx>=0.25
|
|
13
|
+
Requires-Dist: numpy>=1.24
|
|
14
|
+
Requires-Dist: stjames>=0.0.23
|
|
15
|
+
|
|
16
|
+
# Rowan Python Library
|
|
17
|
+
|
|
18
|
+
[](https://pypi.python.org/pypi/rowan-python)
|
|
19
|
+
[](https://github.com/charliermarsh/ruff)
|
|
20
|
+
|
|
21
|
+
The Rowan Python library provides convenient access to the Rowan API from applications written in the Python language.
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
The documentation is available [here](https://docs.rowansci.com/python-api).
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## Issues
|
|
29
|
+
|
|
30
|
+
To report issues, please use the "Issues" tab above.
|
|
31
|
+
|
|
32
|
+
*Corin Wagen, 2023*
|
rowan-python-0.0.1/PKG-INFO
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: rowan-python
|
|
3
|
-
Version: 0.0.1
|
|
4
|
-
Summary: Rowan Python Library
|
|
5
|
-
Author-email: Corin Wagen <corin@rowansci.com>
|
|
6
|
-
Project-URL: Homepage, https://github.com/rowansci/rowan-client
|
|
7
|
-
Project-URL: Bug Tracker, https://github.com/rowansci/rowan-client/issues
|
|
8
|
-
Requires-Python: >=3.8
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
Requires-Dist: cctk>=0.2.18
|
|
11
|
-
Requires-Dist: httpx>=0.25
|
|
12
|
-
Requires-Dist: numpy>=1.24
|
|
13
|
-
Requires-Dist: stjames>=0.0.5
|
|
14
|
-
|
|
15
|
-
# Rowan Python Library
|
|
16
|
-
|
|
17
|
-
The Rowan Python library provides convenient access to the Rowan API from applications written in the Python language.
|
|
18
|
-
|
|
19
|
-
## Documentation
|
|
20
|
-
|
|
21
|
-
The documentation is available [here](https://docs.rowansci.com).
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
|
|
25
|
-
To install, run `pip install rowan-python`.
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
Rowan can be run in either blocking (wait until job is complete) or non-blocking (don't wait) modes.
|
|
30
|
-
Both modes require generation of an API key at [labs.rowansci.com](https://labs.rowansci.com/account/api-keys).
|
|
31
|
-
|
|
32
|
-
For now, molecules are specified through [*cctk*](https://cctk.rtfd.io). Additional ways to specify molecules will be added in the future.
|
|
33
|
-
|
|
34
|
-
Results are returned as dictionaries in the [*stjames*](https://github.com/rowansci/stjames) format.
|
|
35
|
-
|
|
36
|
-
### Blocking
|
|
37
|
-
```
|
|
38
|
-
import cctk
|
|
39
|
-
import rowan
|
|
40
|
-
|
|
41
|
-
rowan.api_key = "rowan-sk..."
|
|
42
|
-
client = rowan.Client()
|
|
43
|
-
|
|
44
|
-
# load molecule by name (cctk can also load in a variety of file formats)
|
|
45
|
-
molecule = cctk.Molecule.new_from_name("cyclobutane")
|
|
46
|
-
|
|
47
|
-
# run calculation remotely and return result
|
|
48
|
-
result = client.compute(molecule, name="opt cyclobutane", method="b97-3c", tasks=["optimize", "charge"])
|
|
49
|
-
print(result)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Non-Blocking
|
|
53
|
-
```
|
|
54
|
-
import cctk
|
|
55
|
-
import rowan
|
|
56
|
-
|
|
57
|
-
rowan.api_key = "rowan-sk..."
|
|
58
|
-
client = rowan.Client(blocking=False)
|
|
59
|
-
|
|
60
|
-
# load molecule by name (cctk can also load in a variety of file formats)
|
|
61
|
-
molecule = cctk.Molecule.new_from_name("cyclobutane")
|
|
62
|
-
|
|
63
|
-
# start calculation and return id
|
|
64
|
-
calc_id = client.compute(molecule, name="opt cyclobutane", method="b97-3c", tasks=["optimize", "charge"])
|
|
65
|
-
|
|
66
|
-
# retrieve result (and status)
|
|
67
|
-
result = client.get(calc_id)
|
|
68
|
-
print(result)
|
|
69
|
-
|
|
70
|
-
# alternately, cancel queued or running calculation
|
|
71
|
-
client.stop(calc_id)
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Issues
|
|
75
|
-
|
|
76
|
-
To report issues, please use the "Issues" tab above.
|
|
77
|
-
|
|
78
|
-
*Corin Wagen, 2023*
|
rowan-python-0.0.1/README.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# Rowan Python Library
|
|
2
|
-
|
|
3
|
-
The Rowan Python library provides convenient access to the Rowan API from applications written in the Python language.
|
|
4
|
-
|
|
5
|
-
## Documentation
|
|
6
|
-
|
|
7
|
-
The documentation is available [here](https://docs.rowansci.com).
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
To install, run `pip install rowan-python`.
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
Rowan can be run in either blocking (wait until job is complete) or non-blocking (don't wait) modes.
|
|
16
|
-
Both modes require generation of an API key at [labs.rowansci.com](https://labs.rowansci.com/account/api-keys).
|
|
17
|
-
|
|
18
|
-
For now, molecules are specified through [*cctk*](https://cctk.rtfd.io). Additional ways to specify molecules will be added in the future.
|
|
19
|
-
|
|
20
|
-
Results are returned as dictionaries in the [*stjames*](https://github.com/rowansci/stjames) format.
|
|
21
|
-
|
|
22
|
-
### Blocking
|
|
23
|
-
```
|
|
24
|
-
import cctk
|
|
25
|
-
import rowan
|
|
26
|
-
|
|
27
|
-
rowan.api_key = "rowan-sk..."
|
|
28
|
-
client = rowan.Client()
|
|
29
|
-
|
|
30
|
-
# load molecule by name (cctk can also load in a variety of file formats)
|
|
31
|
-
molecule = cctk.Molecule.new_from_name("cyclobutane")
|
|
32
|
-
|
|
33
|
-
# run calculation remotely and return result
|
|
34
|
-
result = client.compute(molecule, name="opt cyclobutane", method="b97-3c", tasks=["optimize", "charge"])
|
|
35
|
-
print(result)
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### Non-Blocking
|
|
39
|
-
```
|
|
40
|
-
import cctk
|
|
41
|
-
import rowan
|
|
42
|
-
|
|
43
|
-
rowan.api_key = "rowan-sk..."
|
|
44
|
-
client = rowan.Client(blocking=False)
|
|
45
|
-
|
|
46
|
-
# load molecule by name (cctk can also load in a variety of file formats)
|
|
47
|
-
molecule = cctk.Molecule.new_from_name("cyclobutane")
|
|
48
|
-
|
|
49
|
-
# start calculation and return id
|
|
50
|
-
calc_id = client.compute(molecule, name="opt cyclobutane", method="b97-3c", tasks=["optimize", "charge"])
|
|
51
|
-
|
|
52
|
-
# retrieve result (and status)
|
|
53
|
-
result = client.get(calc_id)
|
|
54
|
-
print(result)
|
|
55
|
-
|
|
56
|
-
# alternately, cancel queued or running calculation
|
|
57
|
-
client.stop(calc_id)
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Issues
|
|
61
|
-
|
|
62
|
-
To report issues, please use the "Issues" tab above.
|
|
63
|
-
|
|
64
|
-
*Corin Wagen, 2023*
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import cctk
|
|
4
|
-
import httpx
|
|
5
|
-
from typing import Optional
|
|
6
|
-
import numpy as np
|
|
7
|
-
import stjames
|
|
8
|
-
from dataclasses import dataclass, field
|
|
9
|
-
import time
|
|
10
|
-
|
|
11
|
-
import rowan
|
|
12
|
-
|
|
13
|
-
API_URL = "https://api.rowansci.com/calculation"
|
|
14
|
-
|
|
15
|
-
# cf. /opt/miniconda3/envs/openai/lib/python3.9/site-packages/openai/__init__.py
|
|
16
|
-
|
|
17
|
-
@dataclass
|
|
18
|
-
class Client:
|
|
19
|
-
blocking: bool = True
|
|
20
|
-
print: bool = True
|
|
21
|
-
ping_interval: int = 5
|
|
22
|
-
|
|
23
|
-
headers: dict = field(init=False)
|
|
24
|
-
|
|
25
|
-
def __post_init__(self):
|
|
26
|
-
self.headers = {"X-API-Key": rowan.utils.get_api_key()}
|
|
27
|
-
|
|
28
|
-
def compute(
|
|
29
|
-
self,
|
|
30
|
-
input_molecule: cctk.Molecule,
|
|
31
|
-
name: Optional[str] = None,
|
|
32
|
-
folder_id: Optional[str] = None,
|
|
33
|
-
**options,
|
|
34
|
-
) -> stjames.Calculation | int:
|
|
35
|
-
atomic_numbers = input_molecule.atomic_numbers.view(np.ndarray)
|
|
36
|
-
geometry = input_molecule.geometry.view(np.ndarray)
|
|
37
|
-
|
|
38
|
-
atoms = list()
|
|
39
|
-
for i in range(input_molecule.num_atoms()):
|
|
40
|
-
atoms.append(
|
|
41
|
-
stjames.Atom(atomic_number=atomic_numbers[i], position=geometry[i])
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
molecule = stjames.Molecule(
|
|
45
|
-
atoms=atoms,
|
|
46
|
-
charge=input_molecule.charge,
|
|
47
|
-
multiplicity=input_molecule.multiplicity,
|
|
48
|
-
)
|
|
49
|
-
settings = stjames.Settings(**options)
|
|
50
|
-
calc = stjames.Calculation(molecules=[molecule], name=name, settings=settings)
|
|
51
|
-
|
|
52
|
-
with httpx.Client() as client:
|
|
53
|
-
response = client.post(
|
|
54
|
-
f"{API_URL}",
|
|
55
|
-
headers=self.headers,
|
|
56
|
-
json={
|
|
57
|
-
"json_data": calc.model_dump(mode="json"),
|
|
58
|
-
"folder_id": folder_id,
|
|
59
|
-
},
|
|
60
|
-
)
|
|
61
|
-
response.raise_for_status()
|
|
62
|
-
response_dict = response.json()
|
|
63
|
-
calc_id = response_dict["id"]
|
|
64
|
-
|
|
65
|
-
if self.print:
|
|
66
|
-
print(f"Calculation {calc_id} submitted")
|
|
67
|
-
|
|
68
|
-
if self.blocking:
|
|
69
|
-
while not response_dict["is_finished"]:
|
|
70
|
-
time.sleep(self.ping_interval)
|
|
71
|
-
response = client.get(f"{API_URL}/{calc_id}", headers=self.headers)
|
|
72
|
-
response_dict = response.json()
|
|
73
|
-
if not response.status_code == 200:
|
|
74
|
-
raise ValueError(
|
|
75
|
-
f"Error {response.status_code}: {response.reason}"
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
# we finished! get proper schema
|
|
79
|
-
response = client.get(
|
|
80
|
-
f"{API_URL}/{calc_id}/stjames", headers=self.headers
|
|
81
|
-
)
|
|
82
|
-
response_dict = response.json()
|
|
83
|
-
|
|
84
|
-
if self.print:
|
|
85
|
-
print(
|
|
86
|
-
f"Calculation {calc_id} completed after {response_dict['elapsed']:.1f} s of CPU time"
|
|
87
|
-
)
|
|
88
|
-
print(
|
|
89
|
-
f"(View the results at labs.rowansci.com/calculations/{calc_id})"
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
return stjames.Calculation.model_validate(response_dict)
|
|
93
|
-
|
|
94
|
-
else:
|
|
95
|
-
return calc_id
|
|
96
|
-
|
|
97
|
-
def get(self, calc_id: int) -> stjames.Calculation:
|
|
98
|
-
with httpx.Client() as client:
|
|
99
|
-
response = client.get(f"{API_URL}/{calc_id}/stjames", headers=self.headers)
|
|
100
|
-
response.raise_for_status()
|
|
101
|
-
response_dict = response.json()
|
|
102
|
-
return stjames.Calculation.model_validate(response_dict)
|
|
103
|
-
|
|
104
|
-
def stop(self, calc_id: int) -> None:
|
|
105
|
-
with httpx.Client() as client:
|
|
106
|
-
response = client.post(f"{API_URL}/{calc_id}/stop", headers=self.headers)
|
|
107
|
-
response.raise_for_status()
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
import rowan
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def get_api_key() -> str:
|
|
7
|
-
api_key = os.environ.get("ROWAN_API_KEY")
|
|
8
|
-
if api_key is not None:
|
|
9
|
-
return api_key
|
|
10
|
-
elif hasattr(rowan, "api_key"):
|
|
11
|
-
return rowan.api_key
|
|
12
|
-
else:
|
|
13
|
-
raise ValueError(
|
|
14
|
-
"No API key provided. You can set your API key using 'rowan.api_key = <API-KEY>', or you can set the environment variable ROWAN_API_KEY=<API-KEY>)."
|
|
15
|
-
)
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: rowan-python
|
|
3
|
-
Version: 0.0.1
|
|
4
|
-
Summary: Rowan Python Library
|
|
5
|
-
Author-email: Corin Wagen <corin@rowansci.com>
|
|
6
|
-
Project-URL: Homepage, https://github.com/rowansci/rowan-client
|
|
7
|
-
Project-URL: Bug Tracker, https://github.com/rowansci/rowan-client/issues
|
|
8
|
-
Requires-Python: >=3.8
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
Requires-Dist: cctk>=0.2.18
|
|
11
|
-
Requires-Dist: httpx>=0.25
|
|
12
|
-
Requires-Dist: numpy>=1.24
|
|
13
|
-
Requires-Dist: stjames>=0.0.5
|
|
14
|
-
|
|
15
|
-
# Rowan Python Library
|
|
16
|
-
|
|
17
|
-
The Rowan Python library provides convenient access to the Rowan API from applications written in the Python language.
|
|
18
|
-
|
|
19
|
-
## Documentation
|
|
20
|
-
|
|
21
|
-
The documentation is available [here](https://docs.rowansci.com).
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
|
|
25
|
-
To install, run `pip install rowan-python`.
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
Rowan can be run in either blocking (wait until job is complete) or non-blocking (don't wait) modes.
|
|
30
|
-
Both modes require generation of an API key at [labs.rowansci.com](https://labs.rowansci.com/account/api-keys).
|
|
31
|
-
|
|
32
|
-
For now, molecules are specified through [*cctk*](https://cctk.rtfd.io). Additional ways to specify molecules will be added in the future.
|
|
33
|
-
|
|
34
|
-
Results are returned as dictionaries in the [*stjames*](https://github.com/rowansci/stjames) format.
|
|
35
|
-
|
|
36
|
-
### Blocking
|
|
37
|
-
```
|
|
38
|
-
import cctk
|
|
39
|
-
import rowan
|
|
40
|
-
|
|
41
|
-
rowan.api_key = "rowan-sk..."
|
|
42
|
-
client = rowan.Client()
|
|
43
|
-
|
|
44
|
-
# load molecule by name (cctk can also load in a variety of file formats)
|
|
45
|
-
molecule = cctk.Molecule.new_from_name("cyclobutane")
|
|
46
|
-
|
|
47
|
-
# run calculation remotely and return result
|
|
48
|
-
result = client.compute(molecule, name="opt cyclobutane", method="b97-3c", tasks=["optimize", "charge"])
|
|
49
|
-
print(result)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Non-Blocking
|
|
53
|
-
```
|
|
54
|
-
import cctk
|
|
55
|
-
import rowan
|
|
56
|
-
|
|
57
|
-
rowan.api_key = "rowan-sk..."
|
|
58
|
-
client = rowan.Client(blocking=False)
|
|
59
|
-
|
|
60
|
-
# load molecule by name (cctk can also load in a variety of file formats)
|
|
61
|
-
molecule = cctk.Molecule.new_from_name("cyclobutane")
|
|
62
|
-
|
|
63
|
-
# start calculation and return id
|
|
64
|
-
calc_id = client.compute(molecule, name="opt cyclobutane", method="b97-3c", tasks=["optimize", "charge"])
|
|
65
|
-
|
|
66
|
-
# retrieve result (and status)
|
|
67
|
-
result = client.get(calc_id)
|
|
68
|
-
print(result)
|
|
69
|
-
|
|
70
|
-
# alternately, cancel queued or running calculation
|
|
71
|
-
client.stop(calc_id)
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Issues
|
|
75
|
-
|
|
76
|
-
To report issues, please use the "Issues" tab above.
|
|
77
|
-
|
|
78
|
-
*Corin Wagen, 2023*
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|