Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Note: on using virtual environments on your own machine, we recommend to use Min
and update the file so that you at least have the following
environment variables :

- MAPI_KEY=the_key_obtained_from_materialsproject
- PMG_MAPI_KEY=the_key_obtained_from_materialsproject

- PMG_VASP_PSP_DIR=path_to_vasp_potcar_files

Expand Down
2 changes: 1 addition & 1 deletion dev_scripts/grain_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_grain_boundary_interface(structure=None,
tilt: tilt in degrees
"""

structure = get_struct_from_mp(structure, MAPI_KEY="")
structure = get_struct_from_mp(structure, PMG_MAPI_KEY="")
sa = SpacegroupAnalyzer(structure)
structure_conventional = sa.get_conventional_standard_structure()
structure = structure_conventional.copy()
Expand Down
4 changes: 2 additions & 2 deletions dev_scripts/hetero_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ def get_matching_lattices(iface1, iface2, max_area=100,


# structure from materials project, use your own key
# gaas = get_struct_from_mp('GaAs', MAPI_KEY="")
# gaas = get_struct_from_mp('GaAs', PMG_MAPI_KEY="")
# sa_gaas = SpacegroupAnalyzer(gaas)
# gaas_cvn = sa_gaas.get_conventional_standard_structure()
# gaas_cvn.to(fmt='poscar', filename='POSCAR_GaAs.vasp')

# cdte = get_struct_from_mp('CdTe', MAPI_KEY="")
# cdte = get_struct_from_mp('CdTe', PMG_MAPI_KEY="")
# sa_cdte = SpacegroupAnalyzer(cdte)
# cdte_cvn = sa_cdte.get_conventional_standard_structure()
# cdte_cvn.to(fmt='poscar', filename='POSCAR_CdTe.vasp')
2 changes: 1 addition & 1 deletion dev_scripts/ligand_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_measurement_task(structure, sol_add={}):
bulk_fireworks = []
bulk_firetasks = []
# pull from matproj, use your own key
bulk = get_struct_from_mp('PbS', MAPI_KEY="")
bulk = get_struct_from_mp('PbS', PMG_MAPI_KEY="")
# primitive --> conventional cell
sa = SpacegroupAnalyzer(bulk)
structure_conventional = sa.get_conventional_standard_structure()
Expand Down
28 changes: 28 additions & 0 deletions examples/CdS_mp-2469_primitive.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# generated using pymatgen
data_CdS
_symmetry_space_group_name_H-M 'P 1'
_cell_length_a 4.20080401
_cell_length_b 4.20080401
_cell_length_c 4.20080401
_cell_angle_alpha 60.00000000
_cell_angle_beta 60.00000000
_cell_angle_gamma 60.00000000
_symmetry_Int_Tables_number 1
_chemical_formula_structural CdS
_chemical_formula_sum 'Cd1 S1'
_cell_volume 52.41821899
_cell_formula_units_Z 1
loop_
_symmetry_equiv_pos_site_id
_symmetry_equiv_pos_as_xyz
1 'x, y, z'
loop_
_atom_site_type_symbol
_atom_site_label
_atom_site_symmetry_multiplicity
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
Cd Cd0 1 0.00000000 0.00000000 0.00000000 1
S S1 1 0.75000000 0.75000000 0.75000000 1
34 changes: 34 additions & 0 deletions examples/GaTe_mp-10009_primitive.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# generated using pymatgen
data_GaTe
_symmetry_space_group_name_H-M 'P 1'
_cell_length_a 4.13459973
_cell_length_b 4.13459973
_cell_length_c 18.42557000
_cell_angle_alpha 90.00000000
_cell_angle_beta 90.00000000
_cell_angle_gamma 120.00000000
_symmetry_Int_Tables_number 1
_chemical_formula_structural GaTe
_chemical_formula_sum 'Ga4 Te4'
_cell_volume 272.78375687
_cell_formula_units_Z 4
loop_
_symmetry_equiv_pos_site_id
_symmetry_equiv_pos_as_xyz
1 'x, y, z'
loop_
_atom_site_type_symbol
_atom_site_label
_atom_site_symmetry_multiplicity
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
Ga Ga0 1 0.66666667 0.33333333 0.68295900 1
Ga Ga1 1 0.33333333 0.66666667 0.18295900 1
Ga Ga2 1 0.33333333 0.66666667 0.31704100 1
Ga Ga3 1 0.66666667 0.33333333 0.81704100 1
Te Te4 1 0.66666667 0.33333333 0.38620400 1
Te Te5 1 0.33333333 0.66666667 0.88620400 1
Te Te6 1 0.33333333 0.66666667 0.61379600 1
Te Te7 1 0.66666667 0.33333333 0.11379600 1
4 changes: 2 additions & 2 deletions examples/create_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

Note: Before using the script, make sure that you do have a valid
api key obtained from the materialsproject website.
Use that to set the MAPI_KEY variable below
Use that to set the PMG_MAPI_KEY variable below
"""

from pymatgen.core import Molecule, Structure
Expand All @@ -23,7 +23,7 @@

if __name__ == '__main__':
# PbS 100 surface with single hydrazine as ligand
# strt=get_struct_from_mp("PbS",MAPI_KEY=MAPI_KEY)
# strt=get_struct_from_mp("PbS",PMG_MAPI_KEY=PMG_MAPI_KEY)
# using smiles_to_xyz.py you can obtain molecule xyz
# using openbabel.
# example structure files are provided and set in dev_scripts
Expand Down
8 changes: 6 additions & 2 deletions examples/hetero_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
from mpinterfaces.interface import Interface
from mpinterfaces.transformations import *
from mpinterfaces.utils import *
from mpinterfaces.old_transformations import generate_all_configs

separation = 3 # in angstroms
nlayers_2d = 2
nlayers_substrate = 2

substrate_bulk = Structure.from_file('POSCAR_substrate')
#substrate_bulk = Structure.from_file('POSCAR_substrate')
substrate_bulk = Structure.from_file('CdS_mp-2469_primitive.cif')
# substrate_bulk = get_struct_from_mp('Ag')
sa_sub = SpacegroupAnalyzer(substrate_bulk)
substrate_bulk = sa_sub.get_conventional_standard_structure()
Expand All @@ -32,7 +34,9 @@
min_vac=25,
primitive=False, from_ase=True)
# substrate_slab = slab_from_file([0,0,1], 'POSCAR_substrate')
mat2d_slab = slab_from_file([0, 0, 1], 'POSCAR_2D')
#mat2d_slab = slab_from_file([0, 0, 1], 'POSCAR_2D')
mat2d_slab = slab_from_file([0, 0, 1], 'GaTe_mp-10009_primitive.cif')

# get the in-plane lattice aligned slabs
# substrate_slab.to(fmt='poscar', filename='POSCAR_substrate_slab.vasp')
mat2d_slab.to(fmt='poscar', filename='POSCAR_mat2d_slab.vasp')
Expand Down
4 changes: 2 additions & 2 deletions examples/naf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ FORMULA: NaF
# below
# if no poscar file is provided, structure will be
# downloaded from the materialsproject database
# note: must set MAPI_KEY evironment variable to
# note: must set PMG_MAPI_KEY evironment variable to
# your key for obtaining data from materialproject
# export MAPI_KEY="key_value"
# export PMG_MAPI_KEY="key_value"
#------------------------------------------------
INCAR:
NSW: 0
Expand Down
2 changes: 1 addition & 1 deletion examples/nanoparticle.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# -----------------------------------
# caution: set the structure wrt which the the miller indices are
# specified. use your own key
structure = get_struct_from_mp('PbS', MAPI_KEY="")
structure = get_struct_from_mp('PbS', PMG_MAPI_KEY="")
# primitive ---> conventional cell
sa = SpacegroupAnalyzer(structure)
structure_conventional = sa.get_conventional_standard_structure()
Expand Down
4 changes: 2 additions & 2 deletions examples/vasp_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from mpinterfaces.interface import Interface
from mpinterfaces.utils import get_run_cmmnd

MAPI_KEY = os.environ.get("MAPI_KEY", "")
PMG_MAPI_KEY = os.environ.get("PMG_MAPI_KEY", "")
# get structure from materialsproject, use your own key
strt = get_struct_from_mp('PbS', MAPI_KEY=MAPI_KEY)
strt = get_struct_from_mp('PbS', PMG_MAPI_KEY=PMG_MAPI_KEY)
# convert from fcc primitive to conventional cell
# the conventional unit cell is used to create the slab
# this is important becasue the hkl specification for the required slab
Expand Down
52 changes: 21 additions & 31 deletions mpinterfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,35 @@
import operator
import warnings

from pymatgen.ext.matproj import MPRester

from monty.serialization import loadfn

__author__ = "Kiran Mathew, Joshua J. Gabriel, Michael Ashton, " \
"Arunima K. Singh, Joshua T. Paul, Seve G. Monahan, " \
"Richard G. Hennig"
__date__ = "March 3 2017"
__version__ = "1.7.0"

PACKAGE_PATH = os.path.dirname(__file__)
PACKAGE_PATH = os.path.dirname(os.path.abspath(__file__))

try:
MPINT_CONFIG = loadfn(os.path.join(PACKAGE_PATH, 'mpint_config.yaml'))
except:
MPINT_CONFIG = {}
warnings.warn('mpint_config.yaml file not configured.')
from .config_loader import CONFIG
from pymatgen.ext.matproj import MPRester

# set environ variables for MAPI_KEY and VASP_PSP_DIR
if MPINT_CONFIG.get('potentials', ''):
os.environ['PMG_VASP_PSP_DIR'] = MPINT_CONFIG.get('potentials', '')
MP_API = MPINT_CONFIG.get('mp_api', '')
if MP_API:
os.environ['MAPI_KEY'] = MP_API
# First, correctly fetch PMG_MAPI_KEY using .get() to handle cases where it might not be set
PMG_MAPI_KEY = CONFIG.get('PMG_MAPI_KEY')

MPR = MPRester(MP_API)
USERNAME = MPINT_CONFIG.get('username', None)
VASP_STD_BIN = MPINT_CONFIG.get('normal_binary', None)
VASP_TWOD_BIN = MPINT_CONFIG.get('twod_binary', None)
VDW_KERNEL = MPINT_CONFIG.get('vdw_kernel', None)
VASP_PSP = MPINT_CONFIG.get('potentials', None)
QUEUE_SYSTEM = MPINT_CONFIG.get('queue_system', None)
QUEUE_TEMPLATE = MPINT_CONFIG.get('queue_template', None)
MPR = MPRester(PMG_MAPI_KEY)

# Other configurations
USERNAME = CONFIG.get('username')
VASP_STD_BIN = CONFIG.get('normal_binary')
VASP_TWOD_BIN = CONFIG.get('twod_binary')
VDW_KERNEL = CONFIG.get('vdw_kernel')
VASP_PSP = CONFIG.get('potentials')
QUEUE_SYSTEM = CONFIG.get('queue_system')
QUEUE_TEMPLATE = CONFIG.get('queue_template')

if not QUEUE_SYSTEM:
QUEUE_SYSTEM = 'slurm'


def get_struct_from_mp(formula, MAPI_KEY="", all_structs=False):

def get_struct_from_mp(formula, PMG_MAPI_KEY="", all_structs=False):
"""
fetches the structure corresponding to the given formula
from the materialsproject database.
Expand All @@ -59,12 +49,12 @@ def get_struct_from_mp(formula, MAPI_KEY="", all_structs=False):
this function returns the one with the lowest energy above the hull
unless all_structs is set to True
"""
if not MAPI_KEY:
MAPI_KEY = os.environ.get("MAPI_KEY", "")
if not MAPI_KEY:
if not PMG_MAPI_KEY:
PMG_MAPI_KEY = os.environ.get("PMG_MAPI_KEY", "")
if not PMG_MAPI_KEY:
print('API key not provided')
print(
'get API KEY from materialsproject and set it to the MAPI_KEY environment variable. aborting ... ')
'get API KEY from materialsproject and set it to the PMG_MAPI_KEY environment variable. aborting ... ')
sys.exit()
with MPR as m:
data = m.get_data(formula)
Expand Down
2 changes: 1 addition & 1 deletion mpinterfaces/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

import numpy as np

from pymatgen import Lattice
from pymatgen.core import Lattice
from pymatgen.core.structure import Structure
from pymatgen.core.surface import SlabGenerator
from pymatgen.io.vasp.inputs import Incar, Poscar
Expand Down
32 changes: 32 additions & 0 deletions mpinterfaces/config_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
from monty.serialization import loadfn

def load_configurations():
expected_keys = [
'PMG_MAPI_KEY', 'PMG_VASP_PSP_DIR', 'username', 'normal_binary',
'twod_binary', 'vdw_kernel', 'potentials', 'queue_system', 'queue_template'
]
configurations = {}

# Attempt to load from .pmgrc.yaml
pmgrc_path = os.path.join(os.path.expanduser('~'), '.pmgrc.yaml')
if os.path.isfile(pmgrc_path):
try:
pmgrc_config = loadfn(pmgrc_path)
for key in expected_keys:
configurations[key] = pmgrc_config.get(key)
except Exception as e:
print(f"Error loading configurations from {pmgrc_path}: {e}")

# Override with environment variables or set to None if not found
for key in expected_keys:
configurations[key] = os.getenv(key.upper(), configurations.get(key))

# Ensure all expected keys are present, even if as None
for key in expected_keys:
if key not in configurations:
configurations[key] = None

return configurations

CONFIG = load_configurations()
8 changes: 5 additions & 3 deletions mpinterfaces/mat2d/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from mpinterfaces import MPINT_CONFIG, VASP_PSP, VASP_STD_BIN, VASP_TWOD_BIN, \
USERNAME, VDW_KERNEL, QUEUE_SYSTEM, MPR

from mpinterfaces import (
VASP_PSP, VASP_STD_BIN, VASP_TWOD_BIN,
USERNAME, VDW_KERNEL, QUEUE_SYSTEM,
QUEUE_TEMPLATE, MPR
)
__author__ = "Michael Ashton, Joshua J. Gabriel, Joshua T. Paul, " \
"Seve G. Monahan"
__version__ = "1.7.0"
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os
import unittest

from mpinterfaces import MPINT_CONFIG
from mpinterfaces import (
VASP_PSP, VASP_STD_BIN, VASP_TWOD_BIN,
USERNAME, VDW_KERNEL, QUEUE_SYSTEM,
QUEUE_TEMPLATE, MPR
)
from mpinterfaces.mat2d.electronic_structure import *
from mpinterfaces.mat2d.electronic_structure.analysis import get_band_edges, \
get_fermi_velocities, plot_band_alignments, plot_band_structure, \
Expand Down
7 changes: 6 additions & 1 deletion mpinterfaces/mat2d/friction/tests/test_friction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import os
import unittest

from mpinterfaces import MPINT_CONFIG
from mpinterfaces import (
VASP_PSP, VASP_STD_BIN, VASP_TWOD_BIN,
USERNAME, VDW_KERNEL, QUEUE_SYSTEM,
QUEUE_TEMPLATE, MPR
)
from mpinterfaces.config_loader import CONFIG
from mpinterfaces.mat2d.friction import *
from mpinterfaces.mat2d.friction.analysis import get_basin_and_peak_locations, \
get_mu_vs_F_N
Expand Down
4 changes: 2 additions & 2 deletions mpinterfaces/mat2d/pourbaix/tests/test_pourbaix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from monty.serialization import loadfn

from mpinterfaces import MP_API
from mpinterfaces import PMG_MAPI_KEY
from mpinterfaces.mat2d.pourbaix import *
from mpinterfaces.mat2d.stability.startup import INCAR_DICT

Expand Down Expand Up @@ -32,7 +32,7 @@ def test_get_experimental_formation_energies(self):
for elt in control_energies:
self.assertEqual(test_energies[elt], control_energies[elt])

@unittest.skipIf(MP_API == None, "API key not set")
@unittest.skipIf(PMG_MAPI_KEY == None, "API key not set")
# def test_relax_references_for_Mo_and_S(self):
# os.chdir(ROOT)
# relax_references(['Mo_pv', 'S'], incar_dict=INCAR_DICT, submit=False)
Expand Down
6 changes: 3 additions & 3 deletions mpinterfaces/mat2d/stability/tests/test_stability.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import unittest

from mpinterfaces import MP_API
from mpinterfaces import PMG_MAPI_KEY
from mpinterfaces.mat2d.stability import *
from mpinterfaces.mat2d.stability.analysis import get_competing_phases, \
get_hull_distance
Expand Down Expand Up @@ -30,13 +30,13 @@ def test_relax_creates_files(self):

class AnalysisTest(unittest.TestCase):

@unittest.skipIf(not MP_API, "API key not set")
@unittest.skipIf(not PMG_MAPI_KEY, "API key not set")
def test_get_hull_distance_for_BiTeCl(self):
os.chdir(ROOT)
os.chdir('BiTeCl')
self.assertEqual(get_hull_distance(), 0.10335952666666692)

@unittest.skipIf(not MP_API, "API key not set")
@unittest.skipIf(not PMG_MAPI_KEY, "API key not set")
def test_get_competing_phases_for_BiTeCl(self):
os.chdir(ROOT)
os.chdir('BiTeCl')
Expand Down
Loading