hjkgrp / molSimplify

molSimplify code
GNU General Public License v3.0
168 stars 49 forks source link

Bidentate Ligand xyz files leading to crash #265

Closed LionFrangoulis closed 1 week ago

LionFrangoulis commented 1 week ago

When trying to generate a compound from bidentate ligands, that aren't part of the database but instead saved as an xyz file, the generator crashes. It appears to be a problem with lines 511-520:

# load ligands and identify the denticity of each
    ligands = []
    for lig in args.lig:
        ligands.append(lig_load(lig)[0])
    # TODO: Found this hardcoded index that will surely fail in certain cases
    # RM 2022/07/15
    number_of_smiles_ligands = 0
    for i, lig in enumerate(ligands):
        if lig.ident == 'smi':
            ligands[i].denticity = len(args.smicat[number_of_smiles_ligands])

if one removes the condition, the code runs, although the resulting angles of the connecting atoms are unpredictable.

Minimum working example, using two bidentate ligand files Ligand6.xyz and Ligand11.xyz:

from molSimplify.Scripts.generator import startgen_pythonic

input_dic={'-core': 'Co',
 '-geometry': 'thd',
 '-coord': '4',
 '-lig': './Ligand6.xyz,./Ligand11.xyz',
 '-keepHs': 'Yes, Yes',
 '-smicat': '[[1, 4], [1,3]]',
 '-ligocc': '1,1',
 '-lignum': '2',
 '-spin': '4',
 '-oxstate': 'II',
 '-rundir': './',
 'calccharge': 'True',
 '-ffoption': 'N'}

try:
    startgen_pythonic(input_dict=input_dic,write=True,flag=True)
except Exception as e:
    print(e)

results in the extended error:


    Traceback (most recent call last):
  File "/home/lion/anaconda3/envs/kitchensink/bin/molsimplify", line 10, in <module>
    sys.exit(main())
  File "/home/lion/anaconda3/envs/kitchensink/lib/python3.9/site-packages/molSimplify/__main__.py", line 184, in main
    startgen(sys.argv, False, gui)
  File "/home/lion/anaconda3/envs/kitchensink/lib/python3.9/site-packages/molSimplify/Scripts/generator.py", line 255, in startgen
    emsg = multigenruns(rundir, args, write_files=write_files)
  File "/home/lion/anaconda3/envs/kitchensink/lib/python3.9/site-packages/molSimplify/Scripts/rungen.py", line 297, in multigenruns
    emsg = rungen(rundir, args, write_files=write_files)
  File "/home/lion/anaconda3/envs/kitchensink/lib/python3.9/site-packages/molSimplify/Scripts/rungen.py", line 593, in rungen
    strfiles, emsg, this_diag = structgen(
  File "/home/lion/anaconda3/envs/kitchensink/lib/python3.9/site-packages/molSimplify/Scripts/structgen.py", line 2962, in structgen
    core3D, complex3D, emsg, this_diag, subcatoms_ext, mligcatoms_ext = mcomplex(
  File "/home/lion/anaconda3/envs/kitchensink/lib/python3.9/site-packages/molSimplify/Scripts/structgen.py", line 2505, in mcomplex
    lig3D, rempi, ligpiatoms = init_ligand(args, lig, tcats, keepHs, i)
  File "/home/lion/anaconda3/envs/kitchensink/lib/python3.9/site-packages/molSimplify/Scripts/structgen.py", line 507, in init_ligand
    lig3D = GetConf(lig3D, args, lig.cat)
  File "/home/lion/anaconda3/envs/kitchensink/lib/python3.9/site-packages/molSimplify/Scripts/distgeom.py", line 588, in GetConf
    LB, UB = GetBoundsMatrices(Conf3D, natoms, catoms, shape)
  File "/home/lion/anaconda3/envs/kitchensink/lib/python3.9/site-packages/molSimplify/Scripts/distgeom.py", line 156, in GetBoundsMatrices
    angle = shape[str(i)+'-'+str(j)]
KeyError: '0-1'
dbkchu commented 1 week ago

Hi @LionFrangoulis, the -smicat flag is only for using SMILES strings to generate the ligand. The code may be trying to interpret the path you have given it as a SMILES string since it is not designed to use ligands from miscellaneous files. You should first add the ligand to the database. Please refer to our tutorials for how to add a ligand from an xyz file to your installation of molSimplify (namely https://hjkgrp.mit.edu/tutorials/2018-05-09-molsimplify-tutorial-10-adding-ligands-molsimplify/). Feel free to reply below if you have any further questions