Commit 6f1bf1d0 authored by Marco Govoni's avatar Marco Govoni
Browse files

Made file name optional in download

parent 027b3f8e
%% Cell type:markdown id: tags:
This tutorial can be downloaded [link](http://greatfire.uchicago.edu/west-public/westpy/raw/master/doc/westpy_100.ipynb).
%% Cell type:markdown id: tags:
# 1.1 Getting Started: Ground State
%% Cell type:markdown id: tags:
We are going to generate an input file for the [QuantumEspresso](https://www.quantum-espresso.org/) code or [Qbox](http://qboxcode.org/). Each code will compute the ground state electronic stucture for the methane molecule using Density Functional Theory.
%% Cell type:markdown id: tags:
## Step 1: Load westpy
%% Cell type:code id: tags:
``` python
from westpy import *
```
%%%% Output: stream
_ _ _____ _____ _____
| | | | ___/ ___|_ _|
| | | | |__ \ `--. | |_ __ _ _
| |/\| | __| `--. \ | | '_ \| | | |
\ /\ / |___/\__/ / | | |_) | |_| |
\/ \/\____/\____/ \_/ .__/ \__, |
| | __/ |
|_| |___/
WEST version : 3.1.0
Today : 2018-06-24 20:30:06.306777
Today : 2018-06-25 06:50:25.196476
%% Cell type:markdown id: tags:
## Step 2: Geometry
%% Cell type:code id: tags:
``` python
geom = Geometry()
```
%% Cell type:markdown id: tags:
Let's define a cubic cell of edge 25 Bohr.
%% Cell type:code id: tags:
``` python
geom.setCell((25,0,0),(0,25,0),(0,0,25))
```
%% Cell type:markdown id: tags:
We load the atomic positions from a XYZ file, available online.
%% Cell type:code id: tags:
``` python
geom.addAtomsFromOnlineXYZ( "http://www.west-code.org/database/gw100/xyz/CH4.xyz" )
```
%% Cell type:markdown id: tags:
We associate pseudopotential files to each species.
%% Cell type:code id: tags:
``` python
geom.addSpecies( "C", "C_ONCV_PBE-1.0.upf", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.0.upf")
geom.addSpecies( "H", "H_ONCV_PBE-1.0.upf", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.0.upf")
geom.addSpecies( "C", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.0.upf")
geom.addSpecies( "H", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.0.upf")
```
%%%% Output: error
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-7844f98bee7b> in <module>()
----> 1 geom.addSpecies( "C", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.0.upf")
2 geom.addSpecies( "H", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.0.upf")
~/Library/Python/3.6/lib/python/site-packages/westpy-3.1.0-py3.6.egg/westpy/geometry.py in addSpecies(self, symbol, url)
69 .. note:: You can use this method to add either upf or xml pseudopotentials. However it is forbidded to mix them.
70 """
---> 71 from westpy import extractFileNameFromUrl
72 fname = extractFileNameFromUrl(url)
73 this_pseudo_format = None
ImportError: cannot import name 'extractFileNameFromUrl'
%% Cell type:markdown id: tags:
## Step 3.1: Ground State
%% Cell type:markdown id: tags:
The ground state calculation is defined by the geometry, a choice of the exchange-correlation functional, and by setting an energy cutoff for the wavefunctions.
%% Cell type:code id: tags:
``` python
gs = GroundState(geom,xc="PBE",ecut=40.0)
```
%% Cell type:markdown id: tags:
We are now able to generate the input file for QuantumEspresso.
%% Cell type:code id: tags:
``` python
gs.generateInputPW()
```
%%%% Output: stream
Generated file: pw.in
%% Cell type:markdown id: tags:
We can inspect the file pw.in
%% Cell type:code id: tags:
``` python
with open("pw.in","r") as file :
data = file.read()
print(data)
```
%%%% Output: stream
&CONTROL
calculation = 'scf'
restart_mode = 'from_scratch'
pseudo_dir = './'
outdir = './'
prefix = 'calc'
wf_collect = .TRUE.
/
&SYSTEM
ibrav = 0
nat = 5
ntyp = 2
ecutwfc = 40.0
nbnd = 8
input_dft = 'PBE'
nosym = .TRUE.
noinv = .TRUE.
/
&ELECTRONS
diago_full_acc = .TRUE.
conv_tol = 1.d-8
/
ATOMIC_SPECIES
C 12.011 C_ONCV_PBE-1.0.upf
H 1.008 H_ONCV_PBE-1.0.upf
ATOMIC_POSITIONS {bohr}
C 0.0 0.0 0.0
H 1.185992116575257 -1.185803143962673 1.185992116575257
H -1.185992116575257 1.185992116575257 1.185992116575257
H -1.185992116575257 -1.185992116575257 -1.185992116575257
H 1.185992116575257 1.185992116575257 -1.185992116575257
K_POINTS {gamma}
CELL_PARAMETERS {bohr}
25.0 0.0 0.0
0.0 25.0 0.0
0.0 0.0 25.0
%% Cell type:markdown id: tags:
We can optionally also download the pseudopotentials files.
%% Cell type:code id: tags:
``` python
gs.downloadPseudopotentials()
```
%%%% Output: stream
Downloaded file: C_ONCV_PBE-1.0.upf , from url: http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.0.upf
Downloaded file: H_ONCV_PBE-1.0.upf , from url: http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.0.upf
%% Cell type:markdown id: tags:
## Step 3.2: Ground State with Qbox
%% Cell type:markdown id: tags:
To generate the input for Qbox we can simply update Species to use the xml formats.
%% Cell type:code id: tags:
``` python
gs.updateSpecies("C", "C_ONCV_PBE-1.0.xml", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml")
gs.updateSpecies("H", "H_ONCV_PBE-1.0.xml", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml")
gs.updateSpecies("C", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml")
gs.updateSpecies("H", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml")
```
%% Cell type:markdown id: tags:
We are now able to generate the input file for QuantumEspresso.
%% Cell type:code id: tags:
``` python
gs.generateInputQbox()
```
%%%% Output: stream
Generated file: qbox.in
%% Cell type:markdown id: tags:
We can inspect the file qbox.in
%% Cell type:code id: tags:
``` python
with open("qbox.in","r") as file :
data = file.read()
print(data)
```
%%%% Output: stream
set cell 25.0 0.0 0.0 0.0 25.0 0.0 0.0 0.0 25.0
species Carbon C_ONCV_PBE-1.0.xml
species Hydrogen H_ONCV_PBE-1.0.xml
atom C1 Carbon 0.0 0.0 0.0
atom H2 Hydrogen 1.185992116575257 -1.185803143962673 1.185992116575257
atom H3 Hydrogen -1.185992116575257 1.185992116575257 1.185992116575257
atom H4 Hydrogen -1.185992116575257 -1.185992116575257 -1.185992116575257
atom H5 Hydrogen 1.185992116575257 1.185992116575257 -1.185992116575257
set ecut 40.0
set wf_dyn JD
set xc PBE
set scf_tol 1.e-8
randomize_wf
run -atomic_density 0 100 5
save gs.xml
%% Cell type:markdown id: tags:
We can optionally also download the pseudopotentials files.
%% Cell type:code id: tags:
``` python
gs.downloadPseudopotentials()
```
%%%% Output: stream
Downloaded file: C_ONCV_PBE-1.0.xml , from url: http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml
Downloaded file: H_ONCV_PBE-1.0.xml , from url: http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml
%% Cell type:code id: tags:
``` python
```
......
......@@ -9,7 +9,7 @@ class Geometry(object) :
>>> geom = Geometry()
>>> geom.setCell( (1,0,0), (0,1,0), (0,0,1) )
>>> geom.addAtom( "Si", (0,0,0) )
>>> geom.addSpecies( "Si", "Si_ONCV_PBE-1.1.upf", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/Si_ONCV_PBE-1.1.upf" )
>>> geom.addSpecies( "Si", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/Si_ONCV_PBE-1.1.upf" )
.. note:: Vectors are set in a.u. by default. If you set units=Angstrom a coversion to a.u. will be made.
......@@ -52,13 +52,11 @@ class Geometry(object) :
isValid = isValid and self.pseudoFormat in ["upf","xml"]
return isValid
#
def addSpecies(self, symbol, fname, url) :
def addSpecies(self, symbol, url) :
"""Adds a species.
:param symbol: chemical symbol
:type symbol: string
:param fname: file name
:type fname: string
:param url: url
:type url: string
......@@ -66,10 +64,12 @@ class Geometry(object) :
>>> from westpy import *
>>> geom = Geometry()
>>> geom.addSpecies( "Si", "Si_ONCV_PBE-1.1.upf", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/Si_ONCV_PBE-1.1.upf" )
>>> geom.addSpecies( "Si", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/Si_ONCV_PBE-1.1.upf" )
.. note:: You can use this method to add either upf or xml pseudopotentials. However it is forbidded to mix them.
"""
from westpy import extractFileNamefromUrl
fname = extractFileNamefromUrl(url)
this_pseudo_format = None
if( fname.endswith("upf") or fname.endswith("UPF")) :
this_pseudo_format = "upf"
......@@ -245,8 +245,8 @@ class Geometry(object) :
>>> from westpy import *
>>> geom = Geometry()
>>> geom.addAtomsFromOnlineXYZ( "http://www.west-code.org/database/gw100/xyz/CH4.xyz" )
>>> geom.addSpecies( "C", "C_ONCV_PBE-1.0.xml", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml")
>>> geom.addSpecies( "H", "H_ONCV_PBE-1.0.xml", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml")
>>> geom.addSpecies( "C", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml")
>>> geom.addSpecies( "H", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml")
>>> nelec = geom.getNumberOfElectrons()
>>> print( nelec )
8
......@@ -279,8 +279,8 @@ class Geometry(object) :
>>> from westpy import *
>>> geom = Geometry()
>>> geom.addAtomsFromOnlineXYZ( "http://www.west-code.org/database/gw100/xyz/CH4.xyz" )
>>> geom.addSpecies( "C", "C_ONCV_PBE-1.0.xml", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml")
>>> geom.addSpecies( "H", "H_ONCV_PBE-1.0.xml", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml")
>>> geom.addSpecies( "C", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.0.xml")
>>> geom.addSpecies( "H", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.0.xml")
>>> geom.downloadPseudopotentials()
.. note:: Pseudopotential files will be downloaded in the current directory.
......@@ -289,4 +289,4 @@ class Geometry(object) :
#
from westpy import download
for key in self.species.keys() :
download( self.species[key]["fname"], self.species[key]["url"])
download( self.species[key]["url"], fname=self.species[key]["fname"] )
......@@ -16,7 +16,7 @@ class GroundState :
>>> geom = Geometry()
>>> geom.setCell( (1,0,0), (0,1,0), (0,0,1) )
>>> geom.addAtom( "Si", (0,0,0) )
>>> geom.addSpecies( "Si", "Si_ONCV_PBE-1.1.upf", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/Si_ONCV_PBE-1.1.upf" )
>>> geom.addSpecies( "Si", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/Si_ONCV_PBE-1.1.upf" )
>>> gs = GroundState(geom,"PBE",30.0)
.. note:: Vectors are set in a.u. by default. If you set units=Angstrom a coversion to a.u. will be made.
......@@ -241,20 +241,18 @@ class GroundState :
"""
self.geom.downloadPseudopotentials()
#
def updateSpecies(self,symbol,fname,url) :
def updateSpecies(self,symbol,url) :
"""Update a species.
:param symbol: chemical symbol
:type symbol: string
:param fname: file name
:type fname: string
:param url: url
:type url: string
:Example:
>>> geom.addSpecies( "Si", "Si_ONCV_PBE-1.1.upf", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/Si_ONCV_PBE-1.1.upf" )
>>> geom.addSpecies( "Si", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/Si_ONCV_PBE-1.1.upf" )
.. note:: You can use this method to add either upf or xml pseudopotentials. However it is forbidded to mix them.
"""
self.geom.addSpecies(symbol,fname,url)
self.geom.addSpecies(symbol,url)
......@@ -2,22 +2,46 @@ from __future__ import print_function
""" Set of utilities."""
def download(fname, url):
def extractFileNamefromUrl(url):
"""Extracts a file name from url.
:param url: url
:type url: string
:returns: file name
:rtype: string
:Example:
>>> from westpy import *
>>> extractFileNamefromUrl("http://www.west-code.org/database/gw100/xyz/CH4.xyz")
"""
#
fname = None
my_url = url[:-1] if url.endswith('/') else url
if my_url.find('/'):
fname = my_url.rsplit('/', 1)[1]
return fname
def download(url,fname=None):
"""Downloads a file from url.
:param fname: file name
:type fname: string
:param url: url
:type url: string
:param fname: file name, optional
:type fname: string
:Example:
>>> from westpy import *
>>> download("CH4.xyz","http://www.west-code.org/database/gw100/xyz/CH4.xyz")
>>> download("http://www.west-code.org/database/gw100/xyz/CH4.xyz")
.. note:: The file will be downloaded in the current directory.
"""
#
if fname is None :
fname = extractFileNamefromUrl(url)
#
from requests import get
# open in binary mode
with open(fname, "wb") as file:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment