Skip to content

Commit

Permalink
Fix error in prefilter_cif
Browse files Browse the repository at this point in the history
  • Loading branch information
choglass committed Nov 17, 2024
1 parent ab3d1b7 commit be3bcf5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
10 changes: 2 additions & 8 deletions cell2mol/final_c2m_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from cell2mol.refcell import process_refcell
from cell2mol.unitcell import process_unitcell
from cell2mol.xyz_molecule import get_molecule
from cell2mol.read_write import prefiter_cif
from cell2mol.read_write import prefilter_cif, exit_with_error

def main():
input, system_type, cell_para, debug_mode = parsing_arguments()
Expand All @@ -17,7 +17,7 @@ def main():
if not os.path.exists(input_path):
exit_with_error(f"Input file not found: {input_path}")
if extension == ".cif":
if prefiter_cif(input_path):
if prefilter_cif(input_path):
handle_cif_file(input_path, system_type, name, current_dir, debug_mode)
else:
exit_with_error("CIF file is not suitable for processing")
Expand Down Expand Up @@ -51,12 +51,6 @@ def handle_xyz_file(input_path, system_type, name, cell_para, current_dir, debug
else:
exit_with_error("Invalid system type for .xyz file", {"system_type": system_type})

def exit_with_error(message):
"""Logs the error message to a file and exits the program."""
error_log_path = os.path.join(os.getcwd(), "error_input.out")
with open(error_log_path, "w") as error_log:
error_log.write(f"Error: {message}\n")
sys.exit(message)

if __name__ == "__main__" or __name__ == "cell2mol.final_c2m_driver":
main()
21 changes: 16 additions & 5 deletions cell2mol/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import re
from collections import defaultdict
import os

#######################
def get_wyckoff_positions(file_path):
Expand Down Expand Up @@ -53,25 +54,35 @@ def get_wyckoff_positions(file_path):
return ref_labels, ref_fracs

#######################
def prefiter_cif(input_path):
def exit_with_error(message):
"""Logs the error message to a file and exits the program."""
error_log_path = os.path.join(os.getcwd(), "error_input.out")
with open(error_log_path, "w") as error_log:
error_log.write(f"Error: {message}\n")
sys.exit(message)

#######################
def prefilter_cif(input_path):

with open(input_path, 'r') as ciffile:
file_content = ciffile.read()
if 'radical' in file_content:
print("Radical found in cif file. STOPPING")
exit_with_error("Radical found in cif file. STOPPING")
return False
elif '_atom_site_fract_x' not in file_content:
print("No fractional coordinates found in cif file. STOPPING")
exit_with_error("No fractional coordinates found in cif file. STOPPING")
return False
elif '?' in file_content:
if "_diffrn_ambient_temperature ?" not in file_content and "_chemical_melting_point ?" not in file_content:
print("Disorder found in cif file. STOPPING")
exit_with_error("Disorder found in cif file. STOPPING")
return False
else:
num_greps = file_content.count('?')
if num_greps > 1:
print("Disorder found in cif file. STOPPING")
exit_with_error("Disorder found in cif file. STOPPING")
return False
else:
return True
else:
print("Cif file is ready for processing")
return True
Expand Down

0 comments on commit be3bcf5

Please sign in to comment.