From f4d3f99b944c78ec305ffdaa8a606b80a7d9dcdc Mon Sep 17 00:00:00 2001 From: my-name Date: Thu, 25 Apr 2024 18:10:49 +0200 Subject: [PATCH] Debugging --- cell2mol/c2m_module.py | 9 +++++++-- cell2mol/charge_assignment.py | 10 +++++----- cell2mol/classes.py | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cell2mol/c2m_module.py b/cell2mol/c2m_module.py index 0dd29a67..a19aaf2d 100644 --- a/cell2mol/c2m_module.py +++ b/cell2mol/c2m_module.py @@ -20,7 +20,9 @@ def cell2mol(newcell: object, reconstruction: bool=True, charge_assignment: bool else: tend = time.time() if debug >= 1: print(f"\nCell Reconstruction Finished Normally. Total execution time: {tend - tini:.2f} seconds") - + else: + return newcell + if charge_assignment: tini = time.time() @@ -36,6 +38,8 @@ def cell2mol(newcell: object, reconstruction: bool=True, charge_assignment: bool tend = time.time() if debug >= 1: print(f"Charge Assignment Finished Normally. Total execution time: {tend - tini:.2f} seconds") # newcell.predict_metal_ox(debug=debug) # predict metal oxidation state using Random Forest model + else: + return newcell if spin_assignment: if not newcell.error_prepare_mols: @@ -43,5 +47,6 @@ def cell2mol(newcell: object, reconstruction: bool=True, charge_assignment: bool newcell.assign_spin(debug=debug) tend = time.time() if debug >= 1: print(f"\nTotal execution time for Spin Assignment: {tend - tini:.2f} seconds") - + else: + return newcell return newcell diff --git a/cell2mol/charge_assignment.py b/cell2mol/charge_assignment.py index 15569061..34324f10 100644 --- a/cell2mol/charge_assignment.py +++ b/cell2mol/charge_assignment.py @@ -417,7 +417,7 @@ def get_protonation_states_specie(specie: object, debug: int=0) -> list: addedlist[idx] = 1 else: mol = ligand.get_parent("molecule") - iscarbene, tmp_element, tmp_added, tmp_metal = check_carbenes(a, ligand, mol) + iscarbene, tmp_element, tmp_added, tmp_metal = check_carbenes(a, ligand) if debug >= 2: print(f" GET_PROTONATION_STATES: Evaluating as carbene and {iscarbene}") if iscarbene: # Carbene identified @@ -698,7 +698,7 @@ def eval_chargelist(atom_charges: list, debug: int=0) -> Tuple[np.ndarray, np.nd return abstotal, abs_atcharge, zwitt ####################################################### -def check_carbenes(atom: object, ligand: object, molecule: object, debug: int=0) -> Tuple[bool, str, int, int]: +def check_carbenes(atom: object, ligand: object, debug: int=0) -> Tuple[bool, str, int, int]: # Function that determines whether a given connected "atom" of a "ligand" of a "molecule" is a carbene # This function is in progress. Ideally, should be able to identify Fischer, Schrock and N-Heterocyclic Carbenes # The former two cases probably require rules that involve other ligands in the molecule, hence why the "molecule" is provided @@ -709,7 +709,7 @@ def check_carbenes(atom: object, ligand: object, molecule: object, debug: int=0) # about Metal electrons: This variable is a way to contemplate cases in which the metal atom is actually contributing with electrons to the metal-ligand bond. # about Metal electrons: In reality, I'm not sure about how to use it correctly, and now is used without much chemical sense - + iscarbene = False element = "H" addedlist = 0 @@ -718,8 +718,8 @@ def check_carbenes(atom: object, ligand: object, molecule: object, debug: int=0) # Initial attempt with Carbenes, but they are much more complex # Looks for Neighbouring N atoms list_of_coord_atoms = [] - for i in atom.adjacency: - list_of_coord_atoms.append(ligand.labels[i]) + for adj in atom.adjacency: + list_of_coord_atoms.append(ligand.get_parent("molecule").labels[adj]) numN = list_of_coord_atoms.count("N") if numN == 2: # it is an N-Heterocyclic carbenes diff --git a/cell2mol/classes.py b/cell2mol/classes.py index b0531efd..2ac91437 100644 --- a/cell2mol/classes.py +++ b/cell2mol/classes.py @@ -1303,9 +1303,9 @@ def get_moleclist(self, blocklist=None, debug: int=0): cov_factor = 1.3 if blocklist is None: blocklist = split_species(self.labels, self.coord, cov_factor=cov_factor, debug=debug) + if blocklist is None: return None if debug > 0: print(f"CELL.MOLECLIST: found {len(blocklist)} blocks") if debug > 0: print(f"CELL.MOLECLIST: {blocklist=}") - if blocklist is None: return None self.moleclist = [] for b in blocklist: