Skip to content

Commit

Permalink
Test run 1
Browse files Browse the repository at this point in the history
  • Loading branch information
choglass committed Jun 2, 2024
1 parent cf7a879 commit 42c39d3
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 87 deletions.
93 changes: 47 additions & 46 deletions cell2mol/new_c2m_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from cell2mol.helper import parsing_arguments
from cell2mol.cif2info import cif_2_info
from cell2mol.classes import cell
from cell2mol.read_write import readinfo, prefiter_cif, writexyz
from cell2mol.read_write import readinfo, prefiter_cif, print_output, writexyz
from cell2mol.new_c2m_module import cell2mol
from cell2mol.other import handle_error
from cell2mol.cell_operations import frac2cart_fromparam
from cell2mol.new_charge_assignment import print_output, assign_charge_state_for_unique_species, balance_charge
from cell2mol.new_charge_assignment import assign_charge_state_for_unique_species, balance_charge

if __name__ == "__main__" or __name__ == "cell2mol.new_c2m_driver":

Expand Down Expand Up @@ -123,9 +123,15 @@
error.close()
sys.stdout = stdout

exit()

##########################################
if refcell.error_case == 0:
if refcell.error_case != 0:
sys.exit(1)
else:
reconstruction = True
charge_assignment = True
spin_assignment = True

# Define new cell object for the unit cell
newcell = cell(name, cell_labels, cell_pos, cell_fracs, cell_vector, cell_param)
newcell.get_subtype("unit_cell")
Expand All @@ -136,54 +142,49 @@
newcell.check_missing_H(debug=debug)
newcell.assess_errors(mode="hydrogens")

print(f"ENTERING cell2mol with debug={debug}")
newcell = cell2mol(newcell, refcell, sym_ops, reconstruction=True, charge_assignment=True, spin_assignment=True, debug=debug)
print(f"ENTERING cell2mol with {debug=}")
print(f"with mode {reconstruction=} {charge_assignment=} {spin_assignment=}")

newcell = cell2mol(newcell, refcell, sym_ops, reconstruction, charge_assignment, spin_assignment, debug=debug)
newcell.assess_errors(mode="unit_cell")

# Save cell object
newcell.save(cell_fname)

if newcell.error_case == 0:
final_charge_distribution, final_charges = balance_charge(newcell.unique_indices, refcell.unique_species, debug=debug)
refcell.unique_species = assign_charge_state_for_unique_species(refcell.unique_species, final_charges[0], debug=debug)
refcell.assign_charges_for_refcell(debug=debug)
refcell.assign_spin(debug=debug)
refcell.create_bonds(debug=debug)

# Update reference cell object
refcell.save(ref_cell_fname)
if newcell.error_case == 0 and charge_assignment :
final_charge_distribution, final_charges = balance_charge(newcell.unique_indices, refcell.unique_species, debug=debug)
refcell.unique_species = assign_charge_state_for_unique_species(refcell.unique_species, final_charges[0], debug=debug)
refcell.assign_charges_for_refcell(debug=debug)
refcell.assign_spin(debug=debug)
refcell.create_bonds(debug=debug)
# Update reference cell object
refcell.save(ref_cell_fname)


output.close()
sys.stdout = stdout

# Summary
surmmary = open(surmmary_fname, "w")
sys.stdout = surmmary
print("*** Reference molecules ***")
print(refcell)
print_output(refcell.refmoleclist)

print("***Unit cell molecules ***")
print(newcell)
print_output(newcell.moleclist)
surmmary.close()
sys.stdout = stdout

# Error handling
case = refcell.error_case
error_fname = os.path.join(current_dir, f"refcell_error_{case}.out")
error = open(error_fname, "w")
sys.stdout = error
handle_error(case)
error.close()
sys.stdout = stdout

case = newcell.error_case
error_fname = os.path.join(current_dir, f"unitcell_error_{case}.out")
error = open(error_fname, "w")
sys.stdout = error
handle_error(case)
error.close()
sys.stdout = stdout

try:
# Summary
surmmary = open(surmmary_fname, "w")
sys.stdout = surmmary
print("*** Reference molecules ***")
print(refcell)
print_output(refcell.refmoleclist)

print("***Unit cell molecules ***")
print(newcell)
print_output(newcell.moleclist)
surmmary.close()
sys.stdout = stdout

# Error handling
case = newcell.error_case
error_fname = os.path.join(current_dir, f"unitcell_error_{case}.out")
error = open(error_fname, "w")
sys.stdout = error
handle_error(case)
error.close()
sys.stdout = stdout
except:
sys.exit(1)
40 changes: 0 additions & 40 deletions cell2mol/new_charge_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,43 +305,3 @@ def prepare_mol (mol):
tmp_atcharge[parent_index] = met.charge

mol.set_charges(int(sum(tmp_atcharge)), atomic_charges=tmp_atcharge, smiles=tmp_smiles)

######################################################
def print_output(moleclist):

for idx, mol in enumerate(moleclist):
if mol.iscomplex:
if hasattr(mol, "totcharge") and hasattr(mol, "spin"):
print(f"{idx}: {mol.subtype}({mol.type}) {mol.formula} {mol.is_haptic=} {mol.totcharge=} {mol.spin=}") #\n {mol.adjnum=}\n {mol.madjnum=} \n {mol.smiles=}")
else:
print(f"{idx}: {mol.subtype}({mol.type}) {mol.formula} {mol.is_haptic=}") # {mol.totcharge=} {mol.spin=}") #\n {mol.adjnum=}\n {mol.madjnum=} \n {mol.smiles=}")
# print(mol.adjnum)
for lig in mol.ligands:
if hasattr(lig, "totcharge") and hasattr(lig, "smiles"):
print(f"|- {lig.subtype}({lig.type}) {lig.formula} {lig.is_haptic=} {lig.denticity=} {lig.totcharge=} {lig.smiles=}")
else :
print(f"|- {lig.subtype}({lig.type}) {lig.formula} {lig.is_haptic=} {lig.denticity=}")# {lig.totcharge=} {lig.smiles=}")
# print(f"|- {lig.connected_idx}")
# print(lig.groups)
for group in lig.groups:
print(f"|-- {group.subtype} ({group.type}) {group.formula} {group.is_haptic=} {group.denticity=} {group.closest_metal.label=}")
for met in group.metals:
print(f"|--- {met.label} {met.mconnec=}")
print("")
for metal in mol.metals:
if hasattr(metal, "charge") and hasattr(metal, "spin"):
print(f"|# {metal.subtype}({metal.type}) {metal.label} {metal.coord_nr=} {metal.coord_geometry} {metal.get_coord_sphere_formula()} {metal.mconnec=} {metal.connec=} {metal.charge=} {metal.spin=}")
else :
print(f"|# {metal.subtype}({metal.type}) {metal.label} {metal.coord_nr=} {metal.coord_geometry} {metal.get_coord_sphere_formula()} {metal.mconnec=} {metal.connec=}") #{metal.charge=} {metal.spin=}
# print(f"|# {metal.get_coord_sphere_formula()}")
# print(f"|# {metal.coord_sphere_formula}")
# print(f"|# {metal.mconnec=} {metal.connec=}")
# print(metal.metal_adjacency)
# for bond in metal.bonds:
# print(f"|--- {bond}")
else:
if hasattr(mol, "totcharge") and hasattr(mol, "spin"):
print(f"{idx}: {mol.subtype}({mol.type}) {mol.formula} {mol.totcharge=} {mol.spin=}\n {mol.smiles}")
else :
print(f"{idx}: {mol.subtype}({mol.type}) {mol.formula}") #{mol.totcharge=} {mol.spin=}\n {mol.smiles}")
print("")
43 changes: 42 additions & 1 deletion cell2mol/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,45 @@ def parse_formula_with_quantity(formula: str):
"quantity": quantity,
"charge": charge
})
return moieties_info
return moieties_info

######################################################
def print_output(moleclist):

print(moleclist[0].refcode)
for idx, mol in enumerate(moleclist):
if mol.iscomplex:
if hasattr(mol, "totcharge") and hasattr(mol, "spin"):
print(f"{idx}: {mol.subtype}({mol.type}) {mol.formula} {mol.is_haptic=} {mol.totcharge=} {mol.spin=}") #\n {mol.adjnum=}\n {mol.madjnum=} \n {mol.smiles=}")
else:
print(f"{idx}: {mol.subtype}({mol.type}) {mol.formula} {mol.is_haptic=}") # {mol.totcharge=} {mol.spin=}") #\n {mol.adjnum=}\n {mol.madjnum=} \n {mol.smiles=}")
# print(mol.adjnum)
for lig in mol.ligands:
if hasattr(lig, "totcharge") and hasattr(lig, "smiles"):
print(f"|- {lig.subtype}({lig.type}) {lig.formula} {lig.is_haptic=} {lig.denticity=} {lig.totcharge=} {lig.smiles=}")
else :
print(f"|- {lig.subtype}({lig.type}) {lig.formula} {lig.is_haptic=} {lig.denticity=}")# {lig.totcharge=} {lig.smiles=}")
# print(f"|- {lig.connected_idx}")
# print(lig.groups)
for group in lig.groups:
print(f"|-- {group.subtype} ({group.type}) {group.formula} {group.is_haptic=} {group.denticity=} {group.closest_metal.label=}")
for met in group.metals:
print(f"|--- {met.label} {met.mconnec=}")
print("")
for metal in mol.metals:
if hasattr(metal, "charge") and hasattr(metal, "spin"):
print(f"|# {metal.subtype}({metal.type}) {metal.label} {metal.coord_nr=} {metal.coord_geometry} {metal.get_coord_sphere_formula()} {metal.mconnec=} {metal.connec=} {metal.charge=} {metal.spin=}")
else :
print(f"|# {metal.subtype}({metal.type}) {metal.label} {metal.coord_nr=} {metal.coord_geometry} {metal.get_coord_sphere_formula()} {metal.mconnec=} {metal.connec=}") #{metal.charge=} {metal.spin=}
# print(f"|# {metal.get_coord_sphere_formula()}")
# print(f"|# {metal.coord_sphere_formula}")
# print(f"|# {metal.mconnec=} {metal.connec=}")
# print(metal.metal_adjacency)
# for bond in metal.bonds:
# print(f"|--- {bond}")
else:
if hasattr(mol, "totcharge") and hasattr(mol, "spin"):
print(f"{idx}: {mol.subtype}({mol.type}) {mol.formula} {mol.totcharge=} {mol.spin=}\n {mol.smiles}")
else :
print(f"{idx}: {mol.subtype}({mol.type}) {mol.formula}") #{mol.totcharge=} {mol.spin=}\n {mol.smiles}")
print("")

0 comments on commit 42c39d3

Please sign in to comment.