...
 
Commits (8)
......@@ -4,7 +4,11 @@
## Developers
- Lan Huang (Argonne National Laboratory)
- He Ma (University of Chicago)
- Aditya Tanikanti (University of Chicago)
- Han Yang (University of Chicago)
## Former Developers
- Aditya Tanikanti (Argonne National Laboratory)
- Huihuo Zheng (Argonne National Laboratory)
......@@ -7,4 +7,4 @@ clean:
rm -rf westpy.egg-info
rm -rf dist
rm -rf build
rm files.txt
rm files.txt
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -56,7 +56,7 @@ master_doc = 'index'
# General information about the project.
project = u'westpy'
copyright = u'2019, Marco Govoni'
copyright = u'2020, Marco Govoni'
author = u'Marco Govoni'
# The version info for the project you're documenting, acts as replacement for
......
......@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
long_description = fh.read()
setup(name='westpy',
version='4.1.0',
version='4.2.0',
packages=find_packages(),
description='Python analysis tools for WEST',
long_description=long_description,
......@@ -27,7 +27,8 @@ setup(name='westpy',
'urllib3',
'prompt-toolkit',
'sphinx',
'sphinx_rtd_theme'
'sphinx_rtd_theme',
'py3Dmol'
],
python_requires='>=2.7, >=3.0, !=3.0.*, !=3.1.*, !=3.2.*, <4',
zip_safe=True)
from __future__ import print_function
from westpy.units import *
from westpy.utils import *
from westpy.atom import *
......@@ -9,7 +7,7 @@ from westpy.dataContainer import *
from westpy.electronicStructure import *
from westpy.session import *
__version__ = '4.1.0'
__version__ = '4.2.0'
def header() :
"""Prints welcome header."""
......
from __future__ import print_function
class Atom(object):
"""Class for representing a single atom.
......@@ -28,4 +26,4 @@ class Atom(object):
el = element(symbol)
#
self.symbol = el.symbol
self.position = np.array(position, float) * units
self.position = np.array(position, dtype="f8") * units
from __future__ import print_function
class DataContainer() :
#
"""Class for representing an in-memory data container.
......
from __future__ import print_function
class ElectronicStructure() :
"""Class for representing an electronic structure calculation.
......
from __future__ import print_function
class Geometry(object) :
"""Class for representing a set of atoms in a periodic cell.
......@@ -121,9 +120,9 @@ class Geometry(object) :
"""
import numpy as np
#
self.cell["a1"] = np.array(a1, float) * units
self.cell["a2"] = np.array(a2, float) * units
self.cell["a3"] = np.array(a3, float) * units
self.cell["a1"] = np.array(a1, dtype="f8") * units
self.cell["a2"] = np.array(a2, dtype="f8") * units
self.cell["a3"] = np.array(a3, dtype="f8") * units
self.cell["volume"] = np.dot(self.cell["a1"], np.cross(self.cell["a2"], self.cell["a3"]))
self.cell["b1"] = 2.0 * np.pi * np.cross(self.cell["a2"], self.cell["a3"]) / self.cell["volume"]
self.cell["b2"] = 2.0 * np.pi * np.cross(self.cell["a3"], self.cell["a1"]) / self.cell["volume"]
......@@ -150,18 +149,45 @@ class Geometry(object) :
self.atoms.append( Atom(symbol, position, units) )
self.isSet["atoms"] = True
#
def __addAtomsFromXYZLines(self, lines ) :
def addFracCoordAtom(self, symbol, frac_coord):
"""adds a single atom by fractional coords
:param symbol: chemical symbol
:type symbol: string
:param position: position
:type position: 3-dim tuple
:Example:
>>> from westpy import *
>>> geom = Geometry()
>>> geom.addFracCoordAtom( "Si", (0,1/3.0,2/3.0) )
"""
if not self.isSet["cell"]:
print('Set cell first!')
return
import numpy as np
from westpy import Atom, Bohr
self.atoms.append(Atom(symbol, tuple(frac_coord[0]*self.cell['a1']+frac_coord[1]*self.cell['a2']+frac_coord[2]*self.cell['a3']), units=Bohr))
self.isSet["atoms"] = True
def __addAtomsFromXYZLines(self, lines, decode=True ) :
"""Adds atoms from XYZ lines.
:param lines: lines read from XYZ file (only one image)
:type lines: list of string
:param decode:
:type bool:
"""
#
from westpy import Angstrom
natoms = int(lines[0])
for line in lines[2:2+natoms] :
symbol, x, y, z = line.split()[:4]
self.addAtom( symbol.decode("utf-8"), (float(x), float(y), float(z)), units=Angstrom )
if decode:
self.addAtom( symbol.decode("utf-8"), (float(x), float(y), float(z)), units=Angstrom )
else:
self.addAtom( symbol, (float(x), float(y), float(z)), units=Angstrom )
#
def addAtomsFromXYZFile(self, fname ) :
"""Adds atoms from XYZ file (only one image).
......@@ -178,7 +204,7 @@ class Geometry(object) :
#
with open(fname,'r') as file:
lines = file.readlines()
self.__addAtomsFromXYZLines(lines)
self.__addAtomsFromXYZLines(lines, decode=False)
#
def addAtomsFromOnlineXYZ(self, url ) :
"""Adds atoms from XYZ file (only one image) located at url.
......@@ -196,7 +222,7 @@ class Geometry(object) :
import urllib.request
with urllib.request.urlopen(url) as response :
lines = response.readlines()
self.__addAtomsFromXYZLines(lines)
self.__addAtomsFromXYZLines(lines, decode=True)
#
def getNumberOfAtoms(self) :
"""Returns number of atoms.
......@@ -294,3 +320,58 @@ class Geometry(object) :
from westpy import download
for key in self.species.keys() :
download( self.species[key]["url"], fname=self.species[key]["fname"] )
def view(self, style='stick',width=800,height=800, ix=1, iy=1, iz=1, debug=False):
"""Display simulation box geom in Angstrom.
ix, iy, iz is the perodic display to system
style can be line, stick, sphere.
:param style:
:param width:
:param height:
:param ix:
:param iy:
:param iz:
:param debug:
:return:
"""
import py3Dmol
import numpy as np
from westpy.units import Angstrom
BOHR2A = 1.0 / Angstrom
a1 = self.cell["a1"] * BOHR2A
a2 = self.cell["a2"] * BOHR2A
a3 = self.cell["a3"] * BOHR2A
nat = self.getNumberOfAtoms()
times = ix * iy * iz
if times > 1:
nat *= times
#generate xyz data
xyz = str(nat) + '\n\n'
for atom in self.atoms:
if times:
for i in range(ix):
for j in range(iy):
for k in range(iz):
xyz += atom.symbol + " " + " ".join(
map(str, atom.position * BOHR2A + i * a1 + j * a2 + k * a3)) + '\n'
#creat viewer
xyzview = py3Dmol.view(width=width, height=height)
xyzview.addModel(xyz, 'xyz')
if debug:
print(xyz)
xyzview.setStyle({style: {}})
#draw the box
a0 = np.array([0.0, 0.0, 0.0],dtype="f8")
from_ = [a0, a1 + a2, a1 + a3, a2 + a3]
to_ = [[a1, a2, a3], [a1, a2, a1 + a2 + a3], [a1, a3, a1 + a2 + a3], [a2, a3, a1 + a2 + a3]]
for frm, li_to in zip(from_, to_):
x0, y0, z0 = frm
for to in li_to:
x1, y1, z1 = to
xyzview.addLine(
{'color': 'blue', 'start': {'x': x0, 'y': y0, 'z': z0}, 'end': {'x': x1, 'y': y1, 'z': z1}});
#show
xyzview.zoomTo()
xyzview.show()
from __future__ import print_function
import requests
import json
from ast import literal_eval
......
from __future__ import print_function
class Session(object):
"""Class for setting up a session, connected to a remove server via rest APIs.
......
from __future__ import print_function
"""Westpy uses Hartree atomic units."""
......
from __future__ import print_function
""" Set of utilities."""
......