I have been able to do calculations in HPC using data available from the legacy version of materialsproject using pymatgen. However after switching into the new version where I am using the new API key from mp-api, I am getting connection error as;
“pymatgen.ext.matproj.MPRestError: HTTPSConnectionPool(host=‘legacy.materialsproject.org’, port=443): Max retries exceeded with url: /rest/v2/api_check (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConnection object at 0x2ac42bc03970>: Failed to establish a new connection: [Errno 101] Network is unreachable’))”
Could anybody help to resolve this issue? Thanks in advance
As of right now, you should import from pymatgen for the legacy API and legacy API key format, and from mp_api from the new API and new API key format.
A compatibility layer will be added to pymatgen in the near future.
Dear Matt,
Thanks for your reply. However, the problem I am facing is not regarding which version. I have been using the new API by from mp_api.client import MPRester after mp-api installation itself and not from the pymatgen . But I am getting error as;
“mp_api.client.core.client.MPRestError: REST query returned with error status code 404 on URL https://legacy.materialsproject.org/rest/materials/mp-2657/?_limit=1&_fields=structure with message:”
followed by a long section starting as '!DOCTYPE html>
Materials Project :: 404
"
I am attaching my code as well for your reference here;
import os
import warnings
warnings.filterwarnings(“ignore”)
from mp_api.client import MPRester #ASE terms
from ase import Atoms
from ase.io import read,write, Trajectory
from ase.optimize import BFGS as BFGS
from ase.calculators.aims import Aims #Pymatgen terms
from pymatgen.core import Structure,Element,Molecule
from pymatgen.analysis.pourbaix_diagram import PourbaixDiagram, PourbaixPlotter, PourbaixEntry
from pymatgen.io.ase import AseAtomsAdaptor #Matplotlib
import matplotlib.pyplot as plt
API_KEY=’ ’
def get_ase_structure(material_id):
mpr= MPRester(API_KEY)
structure=mpr.get_structure_by_material_id(material_id)
ase_structure=AseAtomsAdaptor.get_atoms(structure)
return ase_structure
def fhi_aims_calculator(kgrid):
aims_calc = Aims(
xc=‘pbesol’,
k_grid=kgrid,
spin=‘none’,
relativistic=“atomic_zora scalar”,
relax_unit_cell=“full”,
relax_geometry= “bfgs 5e-3”,
compute_forces=“.true.”,
species_dir=“/u/akhils/softwares/fhi-aims.210716_3/species_defaults/defaults_2020/intermediate”,
run_command=“srun aims.210716_3.scalapack.mpi.x > aims.out”)
return aims_calc
tio2=get_ase_structure(‘mp-2657’)
tio2.set_calculator(fhi_aims_calculator(333))
tio2_energy=tio2.get_potential_energy()
print('Energy: ',tio2_energy)
It seems like there is an error in connecting to pymatgen. Could you pls have a look
The URL in your error message seems to combine the legacy REST URL with the format for the materials endpoint in the new API. Do you have MP_API_ENDPOINT set to the legacy URL in your environment by any chance? Also, which mp_api and pymatgen versions are you using? Does the same error get triggered when you try this minimal example (make sure to run it in a separate script or new notebook):
from mp_api.client import MPRester
# use API key from https://profile.materialsproject.org
with MPRester("your-api-key") as mpr:
mpr.get_structure_by_material_id("mp-149")
I encountered the same error. I ran the program through the anaconda environment and suddenly encountered this error during a certain run. After investigation, it was found that there was a conflict with the dependent environment. Simply build a new virtual environment and input it again:
pip install mp-api
Can solve the problem