Skip to content

Commit

Permalink
apply_symmetry_operations_to_frac
Browse files Browse the repository at this point in the history
  • Loading branch information
choglass committed May 8, 2024
1 parent f2c323d commit a965c1a
Show file tree
Hide file tree
Showing 98 changed files with 78,179 additions and 3,498 deletions.
9 changes: 5 additions & 4 deletions cell2mol/c2m_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from cell2mol.other import handle_error
import ase.io
from cell2mol.cell_operations import frac2cart_fromparam

from cell2mol.cell_operations import cart2frac

# if __name__ != "__main__" and __name__ != "cell2mol.c2m_driver": sys.exit(1)
if __name__ == "__main__" or __name__ == "cell2mol.c2m_driver":
Expand Down Expand Up @@ -73,7 +73,7 @@
atoms = ase.io.read(input_path)

# Get Cartesian coordinates
cartesian_coords = atoms.get_positions()
cartesian_coords = atoms.get_positions("center")

# Get atomic symbols (labels)
atomic_labels = atoms.get_chemical_symbols()
Expand All @@ -92,15 +92,16 @@
# Loads the reference molecules and checks_missing_H
# TODO : reconstruct the unit cell without using reference molecules
# TODO : reconstruct the unit cell using (only reconstruction of) reference molecules and Space group
newcell.get_reference_molecules(ref_labels, ref_fracs,cov_factor=1.3, debug=debug)
newcell.get_reference_molecules(ref_labels, ref_fracs, cov_factor=1.3, debug=debug)
ref_pos = frac2cart_fromparam(ref_fracs, cellparam)
writexyz(current_dir, "Ref_All_{}.xyz".format(name), ref_labels, ref_pos)
writexyz(current_dir, "Ref_All_frac_{}.xyz".format(name), ref_labels, ref_fracs)
if not newcell.has_isolated_H: newcell.check_missing_H(debug=debug)
newcell.assess_errors(ref=True)
newcell.save(ref_cell_fname)
for idx, ref in enumerate(newcell.refmoleclist):
writexyz(current_dir, "Ref_Molecule_{}_{}.xyz".format(name, idx), ref.labels, ref.coord)

writexyz(current_dir, "Ref_Molecule_{}_frac_{}.xyz".format(name, idx), ref.labels, cart2frac(ref.coord, cellvec))
# sys.exit(0)
######################
### CALLS CELL2MOL ###
Expand Down
1 change: 1 addition & 0 deletions cell2mol/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,7 @@ def reconstruct(self, cov_factor: float=None, metal_factor: float=None, debug: i
if Warning:
self.is_fragmented = True
self.error_reconstruction = True

else :
self.is_fragmented = False
self.error_reconstruction = False
Expand Down
35 changes: 35 additions & 0 deletions cell2mol/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import pickle
import sys
import re
from collections import defaultdict

#######################
def prefiter_cif(input_path):
Expand Down Expand Up @@ -340,3 +342,36 @@ def print_unit_cell(cell, output_dir):
for mol in cell.moleclist:
for a in mol.atoms:
print(a.label, a.coord[0], a.coord[1], a.coord[2], file=fil)

############
def extract_chemical_formula_moiety(file_path):
with open(file_path, 'r') as file:
cif_content = file.read()

# Find the chemical formula moiety using regex
pattern = r"_chemical_formula_moiety\s+['\";]([^;'\"]+)['\";]"
match = re.search(pattern, cif_content)
if not match:
raise ValueError("Chemical formula moiety not found.")
formula = match.group(1).strip()
return formula

def parse_formula_with_quantity(formula: str):
element_pattern = r"(\d*)\(?([A-Za-z0-9\s]+)\)?(\d*)(\d+[+-]?)"
moieties_info = []

for match in re.findall(element_pattern, formula):
quantity = int(match[0]) if match[0] else 1
elements = defaultdict(int)
for element, count in re.findall(r"([A-Z][a-z]*)(\d*)", match[1]):
elements[element] += int(count) if count else 1

charge_str = match[3]
charge = int(charge_str[:-1]) * (1 if charge_str.endswith("+") else -1)

moieties_info.append({
"elements": dict(elements),
"quantity": quantity,
"charge": charge
})
return moieties_info
Loading

0 comments on commit a965c1a

Please sign in to comment.