Skip to content

Commit

Permalink
Merge pull request #282 from rolan701/main
Browse files Browse the repository at this point in the history
Update to addtodb.py to add a overwrite feature for input entries, default goes through an openbabel reinterpreter
  • Loading branch information
rolan701 authored Nov 13, 2024
2 parents 5f6b0a6 + f78e4ab commit 3de0cf0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions molSimplify/Scripts/addtodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def initialize_custom_database(globs):
# @param smigrps Ligand groups
# @param smictg Ligand category
# @param ffopt Flag for ligand FF optimization
# @param overwrite Flag for overriding SMILES with OpenBabel Interpretation
# @return Error messages
def addtoldb(smimol, sminame, smident, smicat, smigrps, smictg, ffopt, smichg=None):
def addtoldb(smimol, sminame, smident, smicat, smigrps, smictg, ffopt, overwrite=True, smichg=None):
emsg = False
globs = globalvars()
if not globs.custom_path or not os.path.exists(str(globs.custom_path)):
Expand Down Expand Up @@ -85,8 +86,6 @@ def addtoldb(smimol, sminame, smident, smicat, smigrps, smictg, ffopt, smichg=No
lig.convert2mol3D() # convert to mol3D

shortname = sminame
print("smimol is "+str(smimol))
print("sminame is "+str(sminame))
# sanitize ff options:
if ffopt not in ["A", "B", "BA", "N"]:
print('warning: incompatible ffopt choice. Options are ' +
Expand All @@ -108,7 +107,11 @@ def addtoldb(smimol, sminame, smident, smicat, smigrps, smictg, ffopt, smichg=No
obConversion = openbabel.OBConversion()
obConversion.SetOutFormat("smi")
obConversion.Read(lig.OBMol)
obConversion.WriteFile(lig.OBMol, ligands_folder + sminame+'.smi')
if overwrite == 'True':
obConversion.WriteFile(lig.OBMol, ligands_folder + sminame+'.smi')
else:
with open(ligands_folder + sminame+'.smi', 'w') as f:
f.write(smimol)
# lig.OBMol.write('smi',ligands_folder + sminame+'.smi')
snew = str(sminame)+':'+str(sminame)+'.smi,'+str(shortname)+','+str(css)+','+str(grp)+','+str(ffopt)+','+str(lig.charge)
else:
Expand Down

0 comments on commit 3de0cf0

Please sign in to comment.