Skip to content

Commit 9383eca

Browse files
committed
Ensure examples run
1 parent 996693b commit 9383eca

File tree

5 files changed

+86
-52
lines changed

5 files changed

+86
-52
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ It is easy to customise and compose any of the above workflows.
3939

4040
Workflows in atomate2 written using the [jobflow] library. Workflows are generated using
4141
`Maker` objects, that have a consistent API for modifying input settings and chaining
42-
workflows together. Below, we demonstrate how to run a band structure workflow as
43-
detailed in the [RelaxBandStructure] section of the documentation. In total, 4 VASP
42+
workflows together. Below, we demonstrate how to run a band structure workflow
43+
(see the [documentation][RelaxBandStructure] for more details). In total, 4 VASP
4444
calculations will be performed:
4545

4646
1. A structural optimisation.
@@ -57,21 +57,21 @@ from pymatgen.core import Structure
5757

5858
# construct a rock salt MgO structure
5959
mgo_structure = Structure(
60-
lattice=[[0, 2.13, 2.13], [2.13, 0, 2.13], [2.13, 2.13, 0]],
61-
species=["Mg", "O"],
62-
coords=[[0, 0, 0], [0.5, 0.5, 0.5]],
60+
lattice=[[0, 2.13, 2.13], [2.13, 0, 2.13], [2.13, 2.13, 0]],
61+
species=["Mg", "O"],
62+
coords=[[0, 0, 0], [0.5, 0.5, 0.5]],
6363
)
6464

6565
# make a band structure flow to optimise the structure and obtain the band structure
6666
bandstructure_flow = RelaxBandStructureMaker().make(mgo_structure)
6767

6868
# run the job
69-
run_locally(bandstructure_flow)
69+
run_locally(bandstructure_flow, create_folders=True)
7070
```
7171

72-
In this example, we run execute the workflow immediately. In most cases, you will want
73-
to perform calculations on many materials simulatenously. To achieve this, all atomate2
74-
workflows can be run using the [FireWorks] software. See the
72+
In this example, we run execute the workflow immediately. In many cases, you might want
73+
to perform calculations on several materials simulatenously. To achieve this, all
74+
atomate2 workflows can be run using the [FireWorks] software. See the
7575
[documentation][atomate2_fireworks] for more details.
7676

7777
## Installation
90.3 KB
Loading

docs/src/_static/MgO-dos.png

90.9 KB
Loading

docs/src/user/install.rst

+62-32
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ FireWorks libraries. Briefly:
1919

2020
Running and writing your own workflows are covered in later tutorials. For now, these
2121
topics will be covered in enough depth to get you set up and to help you know where to
22-
troubleshoot if you are having problems.
22+
troubleshoot if you're having problems.
2323

2424
Note that this installation tutorial is VASP-centric since almost all functionality
2525
currently in atomate2 pertains to VASP.
@@ -66,7 +66,7 @@ academic computing clusters as well as systems with a MOM-node style architectur
6666
VASP
6767
----
6868

69-
To get access to VASP on supercomputing resources typically requires that you are added
69+
To get access to VASP on supercomputing resources typically requires that you're added
7070
to a user group on the system you work on after your license is verified. Ensure that
7171
you have access to the VASP executable and that it is functional before starting this
7272
tutorial.
@@ -78,34 +78,30 @@ MongoDB_ is a NoSQL database that stores each database entry as a document, whic
7878
represented in the JSON format (the formatting is similar to a dictionary in Python).
7979
Atomate2 uses MongoDB to:
8080

81-
* to create database of calculation results.
82-
* store the workflows that you want to run as well as their state details (through
81+
* Create a database of calculation results.
82+
* Store the workflows that you want to run as well as their state details (through
8383
FireWorks - optional).
8484

85-
MongoDB must be running and available to accept connections whenever you are running
85+
MongoDB must be running and available to accept connections whenever you're running
8686
workflows. Thus, it is strongly recommended that you have a server to run MongoDB or
8787
(simpler) use a hosting service. Your options are:
8888

89-
* use a commercial service to host your MongoDB instance. These are typically the
89+
- Use a commercial service to host your MongoDB instance. These are typically the
9090
easiest to use and offer high quality service but require payment for larger
91-
databases. `MongoDB Atlas <https://www.mongodb.com/cloud/atlas>`_ offers free 500 MB
92-
which is certainly enough to get started for small to medium size projects, and it is
93-
easy to upgrade or migrate your database if you do exceed the free allocation.
94-
* contact your supercomputing center to see if they offer MongoDB hosting (e.g., NERSC
95-
has this, Google "request NERSC MongoDB database")
96-
* self-host a MongoDB server
97-
98-
If you are just starting, we suggest the first (with a free plan) or second option
91+
databases. `MongoDB Atlas <https://www.mongodb.com/cloud/atlas>`_ offers a free 500 MB
92+
server which is certainly enough to get started for small to medium size projects, and
93+
it is easy to upgrade or migrate your database if you exceed the free allocation.
94+
- Contact your supercomputing center to see if they offer MongoDB hosting (e.g., NERSC
95+
has this, Google "request NERSC MongoDB database").
96+
- Self-host a MongoDB server.
97+
98+
If you're just starting, we suggest the first (with a free plan) or second option
9999
(if available to you). The third option will require you to open up network settings to
100100
accept outside connections properly which can sometimes be tricky.
101101

102-
Next, create a new database and set up two new username/password combinations:
103-
104-
- an admin user
105-
- a read-only user
106-
107-
Keep a record of your credentials - we will configure jobflow to connect to them in a
108-
later step. Also make sure you note down the hostname and port for the MongoDB instance.
102+
Next, create a new database and set up an account with admin access. Keep a record of
103+
your credentials - we will configure jobflow to connect to them in a later step. Also
104+
make sure you note down the hostname and port for the MongoDB instance.
109105

110106
.. note::
111107

@@ -116,15 +112,15 @@ later step. Also make sure you note down the hostname and port for the MongoDB i
116112
centers (e.g., LLNL, PNNL, ARCHER) will run into issues. If you run into connection
117113
issues later in this tutorial, some options are:
118114

119-
* contact your computing center to review their security policy to allow connections
120-
from your MongoDB server (best resolution)
121-
* host your Mongo database on a machine that you are able to securely connect to,
122-
e.g. on the supercomputing network itself (ask a system administrator for help)
123-
* use a proxy service to forward connections from the MongoDB --> login node -->
115+
- Contact your computing center to review their security policy to allow connections
116+
from your MongoDB server (best resolution).
117+
- Host your Mongo database on a machine that you're able to securely connect to,
118+
e.g. on the supercomputing network itself (ask a system administrator for help).
119+
- Use a proxy service to forward connections from the MongoDB --> login node -->
124120
compute node (you might try, for example, `the mongo-proxy tool
125121
<https://github.com/bakks/mongo-proxy>`_).
126-
* set up an ssh tunnel to forward connections from allowed machines (the tunnel must
127-
be kept alive at all times you are running workflows)
122+
- Set up an ssh tunnel to forward connections from allowed machines (the tunnel must
123+
be kept alive at all times you're running workflows).
128124

129125

130126
.. _MongoDB: https://docs.mongodb.com/manual/
@@ -234,7 +230,7 @@ jobflow.yaml
234230
------------
235231

236232
The ``jobflow.yaml`` file contains the credentials of the MongoDB server that will store
237-
calculation outputs. The ``jobflow.json`` file requires you to enter the basic database
233+
calculation outputs. The ``jobflow.yaml`` file requires you to enter the basic database
238234
information as well as what to call the main collection that results are kept in (e.g.
239235
``ouputs``). Note that you should replace the whole ``<<PROPERTY>>`` definition with
240236
your own settings.
@@ -260,6 +256,40 @@ your own settings.
260256
password: <<PASSWORD>>
261257
collection_name: outputs_blobs
262258
259+
.. note::
260+
261+
If you're using a mongoDB hosted on Atlas (using the free plan linked above) the
262+
connection format is slightly different. Instead your ``jobflow.yaml`` file should
263+
contain the following.
264+
265+
.. code-block:: yaml
266+
267+
JOB_STORE:
268+
docs_store:
269+
type: MongoURIStore
270+
uri: mongodb+srv://<<USERNAME>>:<<PASSWORD>>@<<HOST>>/<<DB_NAME>>?retryWrites=true&w=majority
271+
collection_name: outputs
272+
additional_stores:
273+
data:
274+
type: GridFSURIStore
275+
uri: mongodb+srv://<<USERNAME>>:<<PASSWORD>>@<<HOST>>/<<DB_NAME>>?retryWrites=true&w=majority
276+
collection_name: outputs_blobs
277+
278+
The URI key may be different based on the Atlas database you deployed. You can
279+
see the template for the URI string by clicking on "Databases" (under "Deployment"
280+
in the left hand menu) then "Connect" then "Connect your application". Select
281+
Python as the driver and 3.12 as the version. The connection string should now be
282+
displayed in the box.
283+
284+
Note that the username and password are not your login account details for Atlas.
285+
Instead you must add a new database user by selecting "Database Access" (under
286+
"Security" in the left hand menu) and then "Add a new database user".
287+
288+
Secondly, Atlas only allows connections from known IP addresses. You must therefore
289+
add the IP address of your cluster (and any other computers you'll be connecting
290+
from) by clicking "Network Access" (under "Security" in the left hand menu) and then
291+
"Add IP address".
292+
263293
Atomate2 uses two database collections, one for small documents (such as elastic
264294
tensors, structures, and energies) called the ``docs`` store and another for large
265295
documents such as band structures and density of states called the ``data`` store.
@@ -313,7 +343,7 @@ where ``<<INSTALL_DIR>>`` is your installation directory.
313343
Configure pymatgen
314344
==================
315345

316-
If you are planning to run VASP, the last configuration step is to configure pymatgen to
346+
If you're planning to run VASP, the last configuration step is to configure pymatgen to
317347
(required) find the pseudopotentials for VASP and (optional) set up your API key from
318348
the `Materials Project`_.
319349

@@ -383,7 +413,7 @@ or work directory) and create a file called ``relax.py`` containing:
383413
relax_job = RelaxMaker().make(si_structure)
384414
385415
# run the job
386-
run_locally(relax_job)
416+
run_locally(relax_job, create_folders=True)
387417
388418
The ``run_locally`` function is a jobflow command that will execute the workflow on
389419
the current computing resource.
@@ -437,7 +467,7 @@ output.
437467
438468
# query the job store
439469
result = store.query_one(
440-
query={"output.formula_pretty": "Si"}, properties=["output.output.energy_per_atom"]
470+
{"output.formula_pretty": "Si"}, properties=["output.output.energy_per_atom"]
441471
)
442472
print(result)
443473

docs/src/user/running-workflows.rst

+15-11
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Create a Python script named ``mgo_bandstructure.py`` with the following content
8686
bandstructure_flow = RelaxBandStructureMaker().make(mgo_structure)
8787
8888
# run the job
89-
run_locally(bandstructure_flow)
89+
run_locally(bandstructure_flow, create_folders=True)
9090
9191
9292
.. _Running the workflow:
@@ -132,43 +132,47 @@ code, either as a script or on the Python prompt.
132132
133133
from jobflow import SETTINGS
134134
from pymatgen.electronic_structure.plotter import DosPlotter, BSPlotter
135+
from pymatgen.electronic_structure.dos import CompleteDos
136+
from pymatgen.electronic_structure.bandstructure import BandStructureSymmLine
135137
136-
store = jobflow.SETTINGS.JOB_STORE
138+
store = SETTINGS.JOB_STORE
137139
store.connect()
138140
139141
# get the uniform bandstructure from the database
140142
result = store.query_one(
141-
query={"output.task_label": "band structure uniform"},
143+
{"output.task_label": "non-scf uniform"},
142144
properties=["output.vasp_objects.dos"],
143145
load=True, # DOS stored in the data store, so we need to explicitly load it
144146
)
145-
dos = result["output"]["vasp_objects"]["dos"]
147+
dos = CompleteDos.from_dict(result["output"]["vasp_objects"]["dos"])
146148
147149
# plot the DOS
148150
dos_plotter = DosPlotter()
149-
dos_plotter.add_dos(dos)
150-
dos_plotter.save_plot("MgO-dos.pdf", xlim=(-10, 10))
151+
dos_plotter.add_dos_dict(dos.get_element_dos())
152+
dos_plotter.save_plot("MgO-dos.pdf", xlim=(-10, 10), img_format="pdf")
151153
152154
# get the line mode bandstructure from the database
153155
result = store.query_one(
154-
query={"output.task_label": "band structure line"},
156+
{"output.task_label": "non-scf line"},
155157
properties=["output.vasp_objects.bandstructure"],
156158
load=True, # BS stored in the data store, so we need to explicitly load it
157159
)
158-
bandstructure = result["output"]["vasp_objects"]["bandstructure"]
160+
bandstructure = BandStructureSymmLine.from_dict(
161+
result["output"]["vasp_objects"]["bandstructure"]
162+
)
159163
160164
# plot the line mode band structure
161165
bs_plotter = BSPlotter(bandstructure)
162-
bs_plotter.save_plot("MgO-bandstructure.pdf")
166+
bs_plotter.save_plot("MgO-bandstructure.pdf", img_format="pdf")
163167
164168
165169
If you open the saved figures, you should see a plot of your DOS and bandstructure!
166170

167-
.. figure:: _static/MgO-dos.png
171+
.. figure:: ../_static/MgO-dos.png
168172
:alt: MgO density of states
169173

170174

171-
.. figure:: _static/MgO-bandstructure.png
175+
.. figure:: ../_static/MgO-bandstructure.png
172176
:alt: MgO bandstructure
173177

174178

0 commit comments

Comments
 (0)