From 2c4a76b4ef496eef451a54102ed4c3ea6ab93ddb Mon Sep 17 00:00:00 2001 From: my-name Date: Sun, 17 Nov 2024 18:18:03 +0100 Subject: [PATCH] Debugging --- cell2mol/charge_assignment.py | 2 +- cell2mol/classes.py | 7 +++++-- cell2mol/connectivity.py | 4 ++++ cell2mol/helper.py | 6 ++++-- cell2mol/spin.py | 2 +- cell2mol/xyz2mol.py | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cell2mol/charge_assignment.py b/cell2mol/charge_assignment.py index ff04408f..c996fa17 100644 --- a/cell2mol/charge_assignment.py +++ b/cell2mol/charge_assignment.py @@ -744,7 +744,7 @@ def get_charge(charge: int, prot: object, allow: bool=True, embed_chiral: bool=T # Charge_state is initiated ch_state = charge_state(iscorrect, total_charge, atom_charge, mols[0], smiles, charge, allow, prot) - + return ch_state ####################################################### def check_rdkit_obj_connectivity(mol: object, natoms: int, ich: int, debug: int=0): diff --git a/cell2mol/classes.py b/cell2mol/classes.py index 05da7c5f..a6ac8e66 100644 --- a/cell2mol/classes.py +++ b/cell2mol/classes.py @@ -1149,7 +1149,7 @@ def get_connected_groups(self, debug: int=2): if debug > 1: print(f"Metal {self.label} is connected to {group.formula} but not all atoms are connected") conn_idx = [ idx for idx, num in enumerate(tmpadjnum[1:]) if num == 1 ] conn_ligand_indices = [ ligand_indices[idx] for idx, num in enumerate(tmpadjnum[1:]) if num == 1 ] - print(f"get_connected_groups {tmpadjnum[1:]=} {conn_idx=} {conn_ligand_indices=} {ligand_indices=}") + if debug > 1: print(f"get_connected_groups {tmpadjnum[1:]=} {conn_idx=} {conn_ligand_indices=} {ligand_indices=}") splitted_groups = split_group(group, conn_idx, conn_ligand_indices, debug=debug) for g in splitted_groups: self.groups.append(g) @@ -1659,6 +1659,7 @@ def assign_charges (self, debug: int=0): print("ASSIGN_CHARGES: Non-Complex", idx, ref.formula, ref.totcharge, ref.smiles) for idx, mol in enumerate(self.moleclist): + print(f"ASSIGN_CHARGES: Unitcell Molecule {idx}: {mol.formula}") if not mol.iscomplex: for ref in self.refmoleclist: if not ref.iscomplex and (mol.unique_index == ref.unique_index) : @@ -1669,11 +1670,13 @@ def assign_charges (self, debug: int=0): for ref in self.refmoleclist: if ref.iscomplex and (mol.formula == ref.formula): for jdx, lig in enumerate(mol.ligands): - for ref_lig in ref.ligands: + for rdx, ref_lig in enumerate(ref.ligands): if lig.formula == ref_lig.formula: issame = compare_reference_indices(ref_lig, lig, debug=debug) if issame: set_charge_state (ref_lig, lig, mode=2, debug=debug) + else: + print("ERROR: ASSIGN_CHARGES: Ligand", idx, jdx, rdx, lig.formula, ref_lig.totcharge, ref_lig.smiles) for kdx, met in enumerate(mol.metals): for ref_met in ref.metals: if (met.formula == ref_met.formula): diff --git a/cell2mol/connectivity.py b/cell2mol/connectivity.py index 154c2859..303dd2e6 100644 --- a/cell2mol/connectivity.py +++ b/cell2mol/connectivity.py @@ -498,8 +498,12 @@ def compare_reference_indices (ref, mol, debug: int=0): print("Matched", mol.formula, ref.formula, ref.get_parent_indices("reference"), mol.get_parent_indices("reference")) issame = True else: + if debug >= 2: + print("Different indices", mol.formula, ref.formula, ref.get_parent_indices("reference"), mol.get_parent_indices("reference")) issame = False else : + if debug >= 2: + print("Different numbers", mol.formula, ref.formula, ref.get_parent_indices("reference"), mol.get_parent_indices("reference")) issame = False return issame ################################# diff --git a/cell2mol/helper.py b/cell2mol/helper.py index 428c0e3a..e53e16d5 100644 --- a/cell2mol/helper.py +++ b/cell2mol/helper.py @@ -13,7 +13,9 @@ def parsing_arguments(): quiet (bool): quiet flag """ parser = argparse.ArgumentParser( - prog="cell2mol", description="Interprets the crystallography file (.cif) of a molecular crystal, and stores the information in a python cell object" + prog="cell2mol", + description="Interprets the crystallography file (.cif) of a molecular crystal, and stores the information in a python cell object", + add_help=True ) parser.add_argument( @@ -22,7 +24,7 @@ def parsing_arguments(): dest="filename", type=str, required=True, - help="Filename of Input (.info, .xyz, or .cif file)", + help="Filename of Input (.cif or .xyz file)", ) parser.add_argument( diff --git a/cell2mol/spin.py b/cell2mol/spin.py index b6b38b4f..c23b4388 100644 --- a/cell2mol/spin.py +++ b/cell2mol/spin.py @@ -82,7 +82,7 @@ def generate_feature_vector (metal: object, target_prop: str, debug: int = 0) -> valence_elec = metal.get_valence_elec(metal.charge) if debug > 1: print(f"GENERATE_feature_vector: {elem_nr=} {m_ox=} {valence_elec=}") - coord_group = metal.get_connected_groups() + coord_group = metal.get_connected_groups(debug=debug) coord_nr = metal.coord_nr geom_nr = make_geom_list()[metal.coord_geometry] if debug > 1: print(f"GENERATE_feature_vector: {metal.coord_nr=} {metal.coord_geometry=} {geom_nr=}") diff --git a/cell2mol/xyz2mol.py b/cell2mol/xyz2mol.py index 3f643045..4bc88dd8 100644 --- a/cell2mol/xyz2mol.py +++ b/cell2mol/xyz2mol.py @@ -605,7 +605,7 @@ def AC2BO(AC, atoms, charge, allow_charged_fragments=True, use_graph=True): count += 1 if count > max_count : - print(f"Failing AC2BO: {formula=} {charge=} {count=}") + print(f"\tOver maximum counts AC2BO: {formula=} {charge=} {count=}") return best_BO, atomic_valence_electrons # if status: