qzhu2017 / PyXtal

A code to generate atomic structure with symmetry
MIT License
234 stars 59 forks source link

pyxtal.build() function #226

Closed XinYu73 closed 10 months ago

XinYu73 commented 10 months ago

In the build() function, we have following code: wp0 = self.group[0] for sp, wps in zip(species, sites): for wp in wps: if type(wp) is dict: #dict for pair in wp.items(): (key, pos) = pair if we pass species as ['H','H'], and sites :[{'4a': [0.0,0.0,0.0]},{'4b':[0.5,0.5,0.5]}] then we have wps as {'4b':[0.5,0.5,0.5]} and wp as '4b' which will lead to the error that numpy cannot convert string to float

qzhu2017 commented 10 months ago

What's the space group number in your input? Can you post the full input script?

XinYu73 commented 10 months ago
from pyxtal import pyxtal
from pyxtal.lattice import Lattice
import numpy as np

# def build(self, group, species, numIons, lattice, sites):
#         """
#         Build a atomic crystal based on the necessary input

#         Args:
#             group: 225
#             species: ['Na', 'Cl']
#             numIons: [4, 4]
#             lattice: lattice object
#             sites: [{"4a": [0.0, 0.0, 0.0]}, {"4b": [0.5, 0.5, 0.5]}]
#         """
xtal = pyxtal()
xtal.build(
    group=225,
    species=["Na", "Cl"],
    numIons=[4, 4],
    lattice=Lattice.from_matrix(np.diag([2, 2, 2])),
    sites=[{"4a": [0.0, 0.0, 0.0]}, {"4b": [0.5, 0.5, 0.5]}],
)
XinYu73 commented 10 months ago

the error

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[8], line 16
      4 # def build(self, group, species, numIons, lattice, sites):
      5 #         """
      6 #         Build a atomic crystal based on the necessary input
   (...)
     13 #             sites: [{"4a": [0.0, 0.0, 0.0]}, {"4b": [0.5, 0.5, 0.5]}]
     14 #         """
     15 xtal = pyxtal()
---> 16 xtal.build(group = 225,species = ['Na','Cl'],numIons = [4,4],lattice = Lattice.from_matrix(np.diag([2,2,2])),sites = [{"4a": [0.0, 0.0, 0.0]}, {"4b": [0.5, 0.5, 0.5]}])

File [~/workplace/PyXtal/pyxtal/__init__.py:1511](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a2241494c6561726e227d.vscode-resource.vscode-cdn.net/home/xinyu/workplace/high_symmetry_derivative_structure/draft/XXXX_build_database/~/workplace/PyXtal/pyxtal/__init__.py:1511), in pyxtal.build(self, group, species, numIons, lattice, sites)
   1509                 raise RuntimeError("Cannot interpret site", key)
   1510         else: # List of atomic coordinates
-> 1511             pt, _wp, _ = wp0.merge(wp, lattice.matrix, tol=0.1)
   1512             _sites.append(atom_site(_wp, pt, sp))
   1514 self.atom_sites = _sites

File [~/workplace/PyXtal/pyxtal/symmetry.py:2062](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a2241494c6561726e227d.vscode-resource.vscode-cdn.net/home/xinyu/workplace/high_symmetry_derivative_structure/draft/XXXX_build_database/~/workplace/PyXtal/pyxtal/symmetry.py:2062), in Wyckoff_position.merge(self, pt, lattice, tol, orientations)
   2060 PBC = wp.PBC
   2061 group = Group(wp.number, wp.dim)
-> 2062 pt = self.project(pt, lattice, PBC)
   2063 coor = apply_ops(pt, wp)
   2064 if orientations is None:
...
   2288 def project_single(point, rot, trans):
   2289     # move the point in the opposite direction of the translation
   2290     point -= trans

ValueError: could not convert string to float: '4a'
XinYu73 commented 10 months ago

a simple fix is to pass the sites argument as "sites=[[{"4a": [0.0, 0.0, 0.0]}], [{"4b": [0.5, 0.5, 0.5]}]],"

qzhu2017 commented 10 months ago

Yes, you are right. Thanks.