Hi, this might be a simple question but I am having trouble to import class EconNN(NearNeighbors) from pymatgen.analysis.local_env. I can only import NearNeighbors, but not EconNN. Can you please help me with this?
Thanks in advance.
Hi, this might be a simple question but I am having trouble to import class EconNN(NearNeighbors) from pymatgen.analysis.local_env. I can only import NearNeighbors, but not EconNN. Can you please help me with this?
Thanks in advance.
Hi Hemanta,
Can you provide more details on what is not working? Are you getting an error message and if so what is it?
In the future, the best place to get pymatgen debugging advice is actually stack overflow: https://stackoverflow.com/questions/tagged/pymatgen
Just tag your question pymatgen. This helps us a lot as google indexes stack overflow. If someone searches for something similar to your question the answer will show up in their search.
Hi shyamd, thank you so much for your response. I want to import the following class called BrunnerNN_relative from pymatgen.analysis.local_env. I can import NearNeighbors by doing from pymatgen.analysis.local_env import NearNeighbors, but not the BrunnerNN_relative class.
class BrunnerNN_relative(NearNeighbors):
"""
Determine coordination number using Brunner's algorithm which counts the
atoms that are within the largest gap in differences in real space
interatomic distances. This algorithm uses Brunner's method of
of largest relative gap in interatomic distances.
Args:
tol (float): tolerance parameter for bond determination
(default: 1E-4).
cutoff (float): cutoff radius in Angstrom to look for near-neighbor
atoms. Defaults to 8.0.
"""
def __init__(self, tol=1.0e-4, cutoff=8.0):
self.tol = tol
self.cutoff = cutoff
[docs] def get_nn_info(self, structure, n):
site = structure[n]
neighs_dists = structure.get_neighbors(site, self.cutoff)
ds = [i[-1] for i in neighs_dists]
ds.sort()
ns = [ds[i] / ds[i + 1] for i in range(len(ds) - 1)]
d_max = ds[ns.index(max(ns))]
siw = []
for s, dist in neighs_dists:
if dist < d_max + self.tol:
w = ds[0] / dist
siw.append({'site': s,
'image': self._get_image(s.frac_coords),
'weight': w,
'site_index': self._get_original_site(structure, s)})
return siw
In future I will post all related questions in Stackoverflow. Thank you so much for your suggestions.
Hi Hemanta,
We still need an error message to even begin to diagnose what is not working. Ideally, you should supply the following:
Also, please try and format your post. The presentation is key for people to understand what you’re trying to ask. For instance, It took me quite the while to figure out that you had copied and pasted that code from github and that it was not an error message.
Hi shyamd, sorry about that, I will improve it in future. Here is the one with error.
This works but I cannot import the following
from pymatgen.analysis.local_env import BrunnerNN_relative
File “”, line 1, in
from pymatgen.analysis.local_env import BrunnerNN_relative
ImportError: cannot import name ‘BrunnerNN_relative’
In general that sounds like an error where your python is not setup properly or you have an old version of pymatgen. Try updating your pymatgen.
I am using 4.6.2. I think the problem is the way I am calling these functions, which I can’t figure out. The difference is in (). If is (object) I can import, if not I cannot.
class NearNeighbors(object) : I can import
class BrunnerNN_relative(NearNeighbors): I cannot import
Thanks again.
Pymatgen has been on Year-month-day versioning system since close to June of last year, so you’re version is well outdated at this point. You need to upgrade.
Hi shyamd,
Thank you so much for your responses. Now I updated my pymatgen to a recent version and it works.