qzhu2017 / PyXtal_ml

a Python3 library for ML modeling materials properties
MIT License
11 stars 1 forks source link

DDF.py plot_DDF option #6

Closed David-Zagaceta closed 6 years ago

David-Zagaceta commented 6 years ago

@David-Zagaceta will implement a plot_DDF method

qzhu2017 commented 6 years ago

@David-Zagaceta please do not close this issue after you provide some substantial test script. I am not convinced that this have been well implemented.

qzhu2017 commented 6 years ago
Time elapsed for reading the json files: 0.251 seconds
Total number of materials: 844
The chosen feature is: all
Traceback (most recent call last):
  File "main.py", line 26, in <module>
    des = descriptor(struc, feature).merge()
  File "/Users/qiangzhu/Desktop/github/ML-Materials/descriptors/descriptors.py", line 38, in __init__
    self.descriptor['DDF'] = DDF(self.struc).DDF
  File "/Users/qiangzhu/Desktop/github/ML-Materials/descriptors/DDF.py", line 36, in __init__
    self.compute_DDF(crystal)
  File "/Users/qiangzhu/Desktop/github/ML-Materials/descriptors/DDF.py", line 50, in compute_DDF
    self.compute_bond_angles(crystal)
  File "/Users/qiangzhu/Desktop/github/ML-Materials/descriptors/DDF.py", line 172, in compute_bond_angles
    self.structure_array(crystal)
  File "/Users/qiangzhu/Desktop/github/ML-Materials/descriptors/DDF.py", line 158, in structure_array
    self.struc_array = np.hstack((coord_array, covalent_radius_array))
  File "/Users/qiangzhu/.pyenv/versions/3.7.0/lib/python3.7/site-packages/numpy/core/shape_base.py", line 286, in hstack
    return _nx.concatenate(arrs, 0)
ValueError: all the input arrays must have same number of dimensions
qzhu2017 commented 6 years ago

@David-Zagaceta, below is the file which caused the error.

K1 1.0 4.062577 0.000000 2.345530 1.354192 3.830234 2.345530 0.000000 0.000000 4.691060 K 1 direct -0.000000 0.000000 0.000000 K

qzhu2017 commented 6 years ago

@David-Zagaceta please complete it asap. Make sure it is fully in function.

David-Zagaceta commented 6 years ago

@qzhu2017 Which json file did we use to find the previous error?

qzhu2017 commented 6 years ago

@David-Zagaceta first of all, git pull

and then

qiangzhu@u-10-240-0-68:~/Desktop/github/ML-Materials/descriptors$ python DDF.py -c POSCAR-K
Traceback (most recent call last):
  File "DDF.py", line 258, in <module>
    adf = DDF(test)
  File "DDF.py", line 39, in __init__
    self.compute_DDF(crystal)
  File "DDF.py", line 53, in compute_DDF
    self.compute_bond_angles(crystal)
  File "DDF.py", line 168, in compute_bond_angles
    self.structure_array(crystal)
  File "DDF.py", line 154, in structure_array
    self.struc_array = np.hstack((coord_array, covalent_radius_array))
  File "/Users/qiangzhu/.pyenv/versions/3.7.0/lib/python3.7/site-packages/numpy/core/shape_base.py", line 286, in hstack
    return _nx.concatenate(arrs, 0)
ValueError: all the input arrays must have same number of dimensions
David-Zagaceta commented 6 years ago

Found second issue. The default value for R_max, which determines the get_all_neighbors distance is 4. While this specific crystal returns an empty list of neighbors for that value. Upon declaring R_max=5 that problem is fixed.

David-Zagaceta commented 6 years ago

Should we raise an exception when get_all_neighbors returns an empty list?

qzhu2017 commented 6 years ago

Yes, I suggest not increase R_max. Just keep it as 4. Let's just raise an exception when get_all_neighbor returns an empty list, just assign all zero to DDF

qzhu2017 commented 6 years ago

sorry, please increase R_max to 5 and raise an exception as well.

David-Zagaceta commented 6 years ago

Working on it now

David-Zagaceta commented 6 years ago

exception fix has been raised. When the exception is raised the class will return a DDF of 0 values

David-Zagaceta commented 6 years ago

get radii doesn't work in the case of K. In pymatgen K doesn't have a metallic radius. Maybe we need to consider ionic radii? I suspect this may be an issue for group 1 and group 2 elements

David-Zagaceta commented 6 years ago

Also we can return the metallic radii only if ele.is_transition_metal or ele.is_post_transition_metal

Then we could use the atomic radii for alkali and alkaline elements.

qzhu2017 commented 6 years ago
from pymatgen.core.periodic_table import Element

for i in iter(Element): 
    print(i)
    try: 
        print('atomic', Element(i).atomic_radius)
        print('ionic',  Element(i).ionic_radii)
        print('metallic',Element(i).metallic_radius)
    except:
        pass

H atomic 0.25 ang ionic {} He atomic None ionic {} Li atomic 1.45 ang ionic {1: 0.9} metallic 1.52 ang Be atomic 1.05 ang ionic {2: 0.59} metallic 1.12 ang B atomic 0.85 ang ionic {3: 0.41} C atomic 0.7 ang ionic {4: 0.3} N atomic 0.65 ang ionic {-3: 1.32, 3: 0.3, 5: 0.27} O atomic 0.6 ang ionic {-2: 1.26} F atomic 0.5 ang ionic {-1: 1.19, 7: 0.22} Ne atomic None ionic {} Na atomic 1.8 ang ionic {1: 1.16} metallic 1.86 ang Mg atomic 1.5 ang ionic {2: 0.86} metallic 1.6 ang Al atomic 1.25 ang ionic {3: 0.675} metallic 1.43 ang Si atomic 1.1 ang ionic {4: 0.54} P atomic 1.0 ang ionic {3: 0.58, 5: 0.52} S atomic 1.0 ang ionic {-2: 1.7, 4: 0.51, 6: 0.43} Cl atomic 1.0 ang ionic {-1: 1.67, 5: 0.26, 7: 0.41} Ar atomic 0.71 ang ionic {} K atomic 2.2 ang ionic {1: 1.52} metallic 2.381 ang Ca atomic 1.8 ang ionic {2: 1.14} metallic 1.976 ang Sc atomic 1.6 ang ionic {3: 0.885} metallic 1.641 ang Ti atomic 1.4 ang ionic {2: 1.0, 3: 0.81, 4: 0.745} metallic 1.462 ang V atomic 1.35 ang ionic {2: 0.93, 3: 0.78, 4: 0.72, 5: 0.68} metallic 1.347 ang Cr atomic 1.4 ang ionic {2: 0.94} metallic 1.285 ang Mn atomic 1.4 ang ionic {2: 0.97, 3: 0.785, 4: 0.67, 5: 0.47, 6: 0.395, 7: 0.6} metallic 1.292 ang Fe atomic 1.4 ang ionic {2: 0.92, 3: 0.785} metallic 1.277 ang Co atomic 1.35 ang ionic {2: 0.885, 3: 0.75, 4: 0.67} metallic 1.25 ang Ni atomic 1.35 ang ionic {3: 0.74} metallic 1.246 ang Cu atomic 1.35 ang ionic {1: 0.91, 2: 0.87, 3: 0.68} metallic 1.278 ang Zn atomic 1.35 ang ionic {2: 0.88} metallic 1.34 ang Ga atomic 1.3 ang ionic {3: 0.76} metallic 1.35 ang Ge atomic 1.25 ang ionic {2: 0.87, 4: 0.67} metallic 1.39 ang As atomic 1.15 ang ionic {3: 0.72, 5: 0.6} Se atomic 1.15 ang ionic {-2: 1.84, 4: 0.64, 6: 0.56} Br atomic 1.15 ang ionic {-1: 1.82, 3: 0.73, 5: 0.45, 7: 0.53} metallic 1.14 ang Kr atomic None ionic {} Rb atomic 2.35 ang ionic {1: 1.66} metallic 2.537 ang Sr atomic 2.0 ang ionic {2: 1.32} metallic 2.151 ang Y atomic 1.8 ang ionic {3: 1.04} metallic 1.8 ang Zr atomic 1.55 ang ionic {4: 0.86} metallic 1.602 ang Nb atomic 1.45 ang ionic {3: 0.86, 4: 0.82, 5: 0.78} metallic 1.473 ang Mo atomic 1.45 ang ionic {3: 0.83, 4: 0.79, 5: 0.75, 6: 0.73} metallic 1.402 ang Tc atomic 1.35 ang ionic {4: 0.785, 5: 0.74, 7: 0.7} metallic 1.363 ang Ru atomic 1.3 ang ionic {3: 0.82, 4: 0.76, 5: 0.705, 7: 0.52, 8: 0.5} metallic 1.339 ang Rh atomic 1.35 ang ionic {3: 0.805, 4: 0.74, 5: 0.69} metallic 1.345 ang Pd atomic 1.4 ang ionic {1: 0.73, 2: 1.0, 3: 0.9, 4: 0.755} metallic 1.376 ang Ag atomic 1.6 ang ionic {1: 1.29, 2: 1.08, 3: 0.89} metallic 1.445 ang Cd atomic 1.55 ang ionic {2: 1.09} metallic 1.51 ang In atomic 1.55 ang ionic {3: 0.94} metallic 1.67 ang Sn atomic 1.45 ang ionic {4: 0.83} metallic 1.58 ang Sb atomic 1.45 ang ionic {3: 0.9, 5: 0.76} metallic 1.61 ang Te atomic 1.4 ang ionic {-2: 2.07, 4: 1.11, 6: 0.7} I atomic 1.4 ang ionic {-1: 2.06, 5: 1.09, 7: 0.67} Xe atomic None ionic {8: 0.62} Cs atomic 2.6 ang ionic {1: 1.81} metallic 2.719 ang Ba atomic 2.15 ang ionic {2: 1.49} metallic 2.236 ang La atomic 1.95 ang ionic {3: 1.172} metallic 1.877 ang Ce atomic 1.85 ang ionic {3: 1.15, 4: 1.01} metallic 1.707 ang Pr atomic 1.85 ang ionic {3: 1.13, 4: 0.99} metallic 1.828 ang Nd atomic 1.85 ang ionic {2: 1.43, 3: 1.123} metallic 1.821 ang Pm atomic 1.85 ang ionic {3: 1.11} metallic 1.811 ang Sm atomic 1.85 ang ionic {2: 1.36, 3: 1.0979999999999999} metallic 1.804 ang Eu atomic 1.85 ang ionic {2: 1.31, 3: 1.087} metallic 2.041 ang Gd atomic 1.8 ang ionic {3: 1.075} metallic 1.802 ang Tb atomic 1.75 ang ionic {3: 1.063, 4: 0.9} metallic 1.781 ang Dy atomic 1.75 ang ionic {2: 1.21, 3: 1.052} metallic 1.773 ang Ho atomic 1.75 ang ionic {3: 1.041} metallic 1.765 ang Er atomic 1.75 ang ionic {3: 1.03} metallic 1.756 ang Tm atomic 1.75 ang ionic {2: 1.17, 3: 1.02} metallic 1.747 ang Yb atomic 1.75 ang ionic {2: 1.16, 3: 1.008} metallic 1.94 ang Lu atomic 1.75 ang ionic {3: 1.001} metallic 1.735 ang Hf atomic 1.55 ang ionic {4: 0.85} metallic 1.58 ang Ta atomic 1.45 ang ionic {3: 0.86, 4: 0.82, 5: 0.78} metallic 1.47 ang W atomic 1.35 ang ionic {4: 0.8, 5: 0.76, 6: 0.74} metallic 1.41 ang Re atomic 1.35 ang ionic {4: 0.77, 5: 0.72, 6: 0.69, 7: 0.67} metallic 1.375 ang Os atomic 1.3 ang ionic {4: 0.77, 5: 0.715, 6: 0.685, 7: 0.665, 8: 0.53} metallic 1.352 ang Ir atomic 1.35 ang ionic {3: 0.82, 4: 0.765, 5: 0.71} metallic 1.357 ang Pt atomic 1.35 ang ionic {2: 0.94, 4: 0.765, 5: 0.71} metallic 1.387 ang Au atomic 1.35 ang ionic {1: 1.51, 3: 0.99, 5: 0.71} metallic 1.442 ang Hg atomic 1.5 ang ionic {1: 1.33, 2: 1.16} metallic 1.51 ang Tl atomic 1.9 ang ionic {1: 1.64, 3: 1.025} metallic 1.7 ang Pb atomic 1.8 ang ionic {2: 1.33, 4: 0.915} metallic 1.75 ang Bi atomic 1.6 ang ionic {3: 1.17, 5: 0.9} metallic 1.82 ang Po atomic 1.9 ang ionic {4: 1.08, 6: 0.81} metallic 1.53 ang At atomic None ionic {7: 0.76} Rn atomic None ionic {} Fr atomic None ionic {1: 1.94} Ra atomic 2.15 ang ionic {2: 1.62} metallic 2.293 ang Ac atomic 1.95 ang ionic {3: 1.26} metallic 1.878 ang Th atomic 1.8 ang ionic {4: 1.08} metallic 1.798 ang Pa atomic 1.8 ang ionic {3: 1.16, 4: 1.04, 5: 0.92} metallic 1.642 ang U atomic 1.75 ang ionic {3: 1.165, 4: 1.03, 5: 0.9, 6: 0.87} metallic 1.542 ang Np atomic 1.75 ang ionic {2: 1.24, 3: 1.15, 4: 1.01, 5: 0.89, 6: 0.86, 7: 0.85} metallic 1.503 ang Pu atomic 1.75 ang ionic {3: 1.14, 4: 1.0, 5: 0.88, 6: 0.85} metallic 1.523 ang Am atomic 1.75 ang ionic {2: 1.4, 3: 1.115, 4: 0.99} metallic 1.73 ang Cm atomic None ionic {3: 1.11, 4: 0.99} metallic 1.743 ang Bk atomic None ionic {3: 1.1, 4: 0.97} metallic 1.703 ang Cf atomic None ionic {3: 1.09, 4: 0.961} metallic 1.86 ang Es atomic None ionic {} metallic 1.86 ang Fm atomic None ionic {} Md atomic None ionic {} No atomic None ionic {} Lr atomic None ionic {}

David-Zagaceta commented 6 years ago

I'm sorry, just realized that was a consequence of the get_all_neighbors returning an empty list

yanxon commented 6 years ago

Is DDF take this long?

Time elapsed for reading the json files: 0.762 seconds Total number of materials: 50 The chosen feature is: DDF 0 materials have been processed Time elapsed for creating the descriptors: 11565.986 seconds Each material has 179 descriptors Time elapsed for machine learning: 1.583 seconds

-------------SUMMARY of ML--------------

Number of samples: 50 Number of features: 179 Algorithm: GradientBoosting Feature: DDF Property: band_gap r^2: -0.8254 MAE: 0.0029

David-Zagaceta commented 6 years ago

For more complex systems and larger structures the DDF takes a while to compute. This is something I will be working on after implementation of the next descriptor.

qzhu2017 commented 6 years ago

@David-Zagaceta @yanxon Please keep the function as it is for now. Personally, I don't really believe this is an important descriptors. Secondly, I am planning to merge it with our ADF, since they basically share the same computation processes.

qzhu2017 commented 6 years ago

@David-Zagaceta I have updated the test script for DDF.py, however, your code is really slow. I don't know how it works. Please have a look at my updated ADF.py.

David-Zagaceta commented 6 years ago

I will profile DDF later on to see where it's bottle necking. There's a difference in how I calculate my dihedral angle

In your updated ADF.py you calculate the dihedral as

where I calculate my angle as the angle between two planes given by:

qzhu2017 commented 6 years ago

Let's forget about this for now.