Skip to content

Commit

Permalink
Emergency bug fix for convert and example book
Browse files Browse the repository at this point in the history
  • Loading branch information
Spica-Vir committed Nov 2, 2024
1 parent 8abe04a commit ca8a750
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 56 deletions.
8 changes: 2 additions & 6 deletions CRYSTALpytools/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,12 @@ def cry_gui2pmg(gui, vacuum=None, molecule=True):
else:
pbc = (True, True, False)

#Convert the pseudopotential atoms to their original atomic number
atomic_numbers = np.array(gui.atom_number)%200

return Structure(gui.lattice, atomic_numbers, gui.atom_positions, coords_are_cartesian=True)

#Convert the pseudopotential / different basis set atoms to their original atomic number
atomic_numbers = np.array(gui.atom_number)%100
if gui.dimensionality == 3:
pbc = (True, True, True)

latt = Lattice(gui.lattice, pbc=pbc)

return Structure(latt, gui.atom_number, gui.atom_positions, coords_are_cartesian=True)


Expand Down
10 changes: 5 additions & 5 deletions examples/convert/conv_mgoOpt.gui
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@
0.000000000000 0.000000000000 0.000000000000
8
12 0.000000000000E+00 0.000000000000E+00 0.000000000000E+00
12 -2.315657104494E+00 2.293835410510E-01 1.890726108420E+00
12 -1.879447413078E+00 2.326935799837E+00 -2.068261503660E-01
12 2.315657104494E+00 -2.293835410510E-01 -1.890726108420E+00
12 1.879447413078E+00 -2.326935799837E+00 2.068261503660E-01
12 0.000000000000E+00 2.120109649471E+00 2.120109649471E+00
8 -2.097552258786E+00 2.338214495179E+00 1.902004803763E+00
8 2.181048457080E-01 2.108830954128E+00 1.127869534300E-02
8 2.181048457080E-01 4.228940603599E+00 2.131388344814E+00
8 -1.661342567370E+00 4.435766753965E+00 -1.955474550230E-01
8 2.533761950202E+00 1.879447413078E+00 -1.879447413078E+00
8 -2.097552258786E+00 2.181048457080E-01 -2.181048457080E-01
8 -2.181048457080E-01 1.127869534300E-02 2.108830954128E+00
225 48
94 changes: 49 additions & 45 deletions examples/convert/convert.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"angles: 60.000000 60.000000 60.000000\n",
"pbc : True True True\n",
"Sites (2)\n",
" # SP a b c\n",
"--- ---- ---- ---- ----\n",
" 0 Mg 0 0 0\n",
" 1 O -0.5 -0.5 -0.5\n"
" # SP a b c\n",
"--- ---- --- --- ----\n",
" 0 Mg 0 0 0\n",
" 1 O 0.5 0.5 -0.5\n"
]
}
],
Expand Down Expand Up @@ -251,6 +251,48 @@
"print(struc)"
]
},
{
"cell_type": "markdown",
"id": "933a782e-769d-4981-8962-93a600cb29c8",
"metadata": {},
"source": [
"Alternatively, a 2D periodic structure is returned with default 500 Angstrom along non-periodic direction(s)."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f92efcfc-8d2a-472d-98e4-2609fcddced9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Full Formula (Mg2 O4)\n",
"Reduced Formula: MgO2\n",
"abc : 3.009789 3.009789 500.000000\n",
"angles: 90.000000 90.000000 90.000000\n",
"pbc : True True False\n",
"Sites (6)\n",
" # SP a b c\n",
"--- ---- --- --- ---------\n",
" 0 Mg 0 0.5 0.002128\n",
" 1 Mg 0.5 0 -0.002128\n",
" 2 O 0 0.5 -0.002128\n",
" 3 O 0.5 0 0.002128\n",
" 4 O 0.5 0 -0.006128\n",
" 5 O 0 0.5 0.006128\n"
]
}
],
"source": [
"from CRYSTALpytools.convert import cry_gui2pmg\n",
"\n",
"struc = cry_gui2pmg('conv_mgo100.gui')\n",
"print(struc)"
]
},
{
"cell_type": "markdown",
"id": "3fa9dd99",
Expand All @@ -269,7 +311,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "ce4f04fd",
"metadata": {
"tags": []
Expand Down Expand Up @@ -300,7 +342,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "4be2730e",
"metadata": {
"tags": []
Expand All @@ -312,7 +354,7 @@
"<Axes: xlabel='$\\\\mathrm{Wave\\\\ Vector}$', ylabel='$\\\\mathrm{E\\\\ -\\\\ E_f\\\\ (eV)}$'>"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -685,44 +727,6 @@
"!cat conv_toluene.xyz"
]
},
{
"cell_type": "markdown",
"id": "2be4b39c-739b-4f13-9b78-d0887093c1e4",
"metadata": {},
"source": [
"## Saving data grids\n",
"\n",
"### The 'cry_cube2xsf()' function\n",
"Convert 3D scalar field data in CUBE file into [XCrySDen](http://www.xcrysden.org/) XSF files, which enables periodicity of the structure and can be visualized by popular software such as [XCrySDen](http://www.xcrysden.org/), [VESTA](https://jp-minerals.org/vesta/en/) or [VMD](https://www.ks.uiuc.edu/Research/vmd/).\n",
"\n",
"It is important that CUBE file follows CRYSTAL convention (See [API documentations](https://crystal-code-tools.github.io/CRYSTALpytools/crystalpytools.convert.html#CRYSTALpytools.convert.cry_cube2xsf)).\n",
"\n",
"For low dimensional systmes it's also important to specify the periodicity to avoid potential file loading error of XCrySDen.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "0a1f68ed-3330-412b-a8db-e058d0d3381a",
"metadata": {},
"outputs": [],
"source": [
"from CRYSTALpytools.convert import cry_cube2xsf\n",
"\n",
"cry_cube2xsf('../charge_density/dens_MgO.cube', 'conv_MgO.xsf', 'SLAB')"
]
},
{
"cell_type": "markdown",
"id": "0f4dc5a3-54f1-43e6-b3d0-6c17b4945a02",
"metadata": {},
"source": [
"Visualize the 3\\*3 supercell in VESTA.\n",
"\n",
"<img src=\"./conv_MgO.png\" width=\"480\">"
]
},
{
"cell_type": "markdown",
"id": "2c2859bc-a391-459d-9a20-5b261865ad9d",
Expand Down

0 comments on commit ca8a750

Please sign in to comment.