Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
koerstz authored Oct 2, 2021
2 parents 413fadb + 642ed07 commit d3982c1
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions xyz2mol.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def clean_charges(mol):


def BO2mol(mol, BO_matrix, atoms, atomic_valence_electrons,
mol_charge, allow_charged_fragments=True):
mol_charge, allow_charged_fragments=True, use_atom_maps=False):
"""
based on code written by Paolo Toscani
Expand Down Expand Up @@ -311,20 +311,25 @@ def BO2mol(mol, BO_matrix, atoms, atomic_valence_electrons,
atomic_valence_electrons,
BO_valences,
BO_matrix,
mol_charge)
mol_charge,
use_atom_maps)
else:
mol = set_atomic_radicals(mol, atoms, atomic_valence_electrons, BO_valences)
mol = set_atomic_radicals(mol, atoms, atomic_valence_electrons, BO_valences,
use_atom_maps)

return mol


def set_atomic_charges(mol, atoms, atomic_valence_electrons,
BO_valences, BO_matrix, mol_charge):
BO_valences, BO_matrix, mol_charge,
use_atom_maps):
"""
"""
q = 0
for i, atom in enumerate(atoms):
a = mol.GetAtomWithIdx(i)
if use_atom_maps:
a.SetAtomMapNum(i+1)
charge = get_atomic_charge(atom, atomic_valence_electrons[atom], BO_valences[i])
q += charge
if atom == 6:
Expand All @@ -344,14 +349,17 @@ def set_atomic_charges(mol, atoms, atomic_valence_electrons,
return mol


def set_atomic_radicals(mol, atoms, atomic_valence_electrons, BO_valences):
def set_atomic_radicals(mol, atoms, atomic_valence_electrons, BO_valences,
use_atom_maps):
"""
The number of radical electrons = absolute atomic charge
"""
for i, atom in enumerate(atoms):
a = mol.GetAtomWithIdx(i)
if use_atom_maps:
a.SetAtomMapNum(i+1)
charge = get_atomic_charge(
atom,
atomic_valence_electrons[atom],
Expand Down Expand Up @@ -473,7 +481,8 @@ def AC2BO(AC, atoms, charge, allow_charged_fragments=True, use_graph=True):
return best_BO, atomic_valence_electrons


def AC2mol(mol, AC, atoms, charge, allow_charged_fragments=True, use_graph=True):
def AC2mol(mol, AC, atoms, charge, allow_charged_fragments=True,
use_graph=True, use_atom_maps=False):
"""
"""

Expand All @@ -492,7 +501,8 @@ def AC2mol(mol, AC, atoms, charge, allow_charged_fragments=True, use_graph=True)
atoms,
atomic_valence_electrons,
charge,
allow_charged_fragments=allow_charged_fragments)
allow_charged_fragments=allow_charged_fragments,
use_atom_maps=use_atom_maps)

# If charge is not correct don't return mol
if Chem.GetFormalCharge(mol) != charge:
Expand Down Expand Up @@ -628,7 +638,7 @@ def get_AC(mol, covalent_factor=1.3):
return AC


def xyz2AC_huckel(atomicNumList,xyz,charge):
def xyz2AC_huckel(atomicNumList, xyz, charge):
"""
args
Expand Down Expand Up @@ -684,12 +694,9 @@ def chiral_stereo_check(mol):
return


def xyz2mol(atoms, coordinates,
charge=0,
allow_charged_fragments=True,
use_graph=True,
use_huckel=False,
embed_chiral=True):
def xyz2mol(atoms, coordinates, charge=0, allow_charged_fragments=True,
use_graph=True, use_huckel=False, embed_chiral=True,
use_atom_maps=False):
"""
Generate a rdkit molobj from atoms, coordinates and a total_charge.
Expand All @@ -715,9 +722,10 @@ def xyz2mol(atoms, coordinates,

# Convert AC to bond order matrix and add connectivity and charge info to
# mol object
new_mols = AC2mol(mol, AC, atoms, charge,
allow_charged_fragments=allow_charged_fragments,
use_graph=use_graph)
new_mol = AC2mol(mol, AC, atoms, charge,
allow_charged_fragments=allow_charged_fragments,
use_graph=use_graph,
use_atom_maps=use_atom_maps)

# Check for stereocenters and chiral centers
if embed_chiral:
Expand Down

0 comments on commit d3982c1

Please sign in to comment.