Skip to content

Commit

Permalink
fix the get_all_positions function and add the new_struc_wo_energy fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
qzhu2017 committed Apr 24, 2024
1 parent 411e42f commit ec07cd2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
47 changes: 47 additions & 0 deletions pyxtal/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,53 @@ def compute(self, row, work_dir, skf_dir):
self.db.update(row.id, data=data)
print('updated the data for', row.csd_code)

class database_topology():
"""
This is a database class to process atomic crystal data
Args:
db_name: *.db format from ase database
"""

def __init__(self, db_name):
self.db_name = db_name
#if not os.path.exists(db_name):
# raise ValueError(db_name, 'doesnot exist')

self.db = connect(db_name)
self.keys = ['space_group', 'spg_num',
'topology', 'ff_energy',
'similarity',
]

def vacuum(self):
self.db.vacuum()


def get_pyxtal(self, id):
from pyxtal import pyxtal
from pyxtal.util import ase2pymatgen

atom = self.db.get_atoms(id=id)
pmg = ase2pymatgen(atom)
xtal = pyxtal()
try:
xtal.from_seed(pmg)
return xtal
except:
print('Cannot load the structure')


def get_all_xtals(self):
xtals = []
for row in self.db.select():
xtal = self.get_pyxtal(id=row.id)
if xtal is not None and xtal.valid:
xtal.ff_energy = row.ff_energy
xtal.similarity = row.similarity
xtal.topology = row.topology
xtals.append(xtal)
return xtals

if __name__ == "__main__":
# open
Expand Down
3 changes: 2 additions & 1 deletion pyxtal/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ def get_all_positions(self, pos):
[0.5, 0.5, 0.5]])
"""

pos0, _, _ = self.merge(pos, np.eye(3), 0.01)
pos0 = self.search_generator(pos)
res = self.apply_ops(pos0)
res -= np.floor(res)
return res
Expand Down Expand Up @@ -2165,6 +2165,7 @@ def merge(self, pt, lattice, tol, orientations=None, group=None):
if y[0] == 0 and y[1] == 0:
pass
else:
#print(dm); print(y)
passed_distance_check = False
break

Expand Down
32 changes: 32 additions & 0 deletions pyxtal/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,38 @@ def new_struc(xtal, xtals):
return False
return True

def new_struc_wo_energy(xtal, xtals):
"""
check if this is a new structure
Args:
xtal: input structure
xtals: list of reference structures
Return:
`None` or the id of matched structure
"""
import pymatgen.analysis.structure_matcher as sm

if xtal is None:
return False
else:
pmg_s1 = xtal.to_pymatgen()
pmg_s1.remove_species("H")
vol1 = pmg_s1.lattice.volume

for xtal2 in xtals:
#print(rep); print(rep2)
pmg_s2 = xtal2.to_pymatgen()
vol2 = pmg_s2.lattice.volume
if abs(vol1-vol2)/vol1<5e-2:
pmg_s2.remove_species("H")
if sm.StructureMatcher().fit(pmg_s1, pmg_s2):
#print(pmg_s2); import sys; sys.exit()
return False
return True



if __name__ == "__main__":
from argparse import ArgumentParser
Expand Down

0 comments on commit ec07cd2

Please sign in to comment.