I used openbabel to convert the .cif files to .smi. Here are parts of the .smi corresponding to two .cif files (I have many .cif files):

[C](=[C]\F)\F.C(=C(\[C][C]O[Zn@]12O[C](c3ccc([C]4O[Zn](O[C](c5ccc(C(=O)O[Zn]([O])O[C](c6ccc(C(=O)O[Zn](OC(=O)c7ccc(C(=O)O2)cc7)[O])cc6)O[Zn]O[C])cc5)O[Zn]O[Zn]O4)O[C][C]/C(=C(\[C][C]/C(=[C]/F)/F)/F)/F)cc3)O[Zn]([O])O1)/F)(\[C][C]/C(=C(\[C])/F)/F)/F.c12C(=O)O[Zn](O[C])OC(=O)c3ccc([C](O[Zn@@]4([O])O[C](c5ccc([C]6O[Zn](O[C](c7ccc(C(=O)O[Zn](OC(=O)c(cc1)cc2)O[C])cc7)O[Zn]O[Zn]O6)[O])cc5)O[Zn](O[C][C]/C(=C(\[C])/F)/F)O4)O[Zn])cc3.[C]/C(=C(\[C])/F)/F.[C]/C(=C(\[C])/F)/F.[C]/C(=C(\[C])/F)/F.[C]/C(=[C]/F)/F.[C](=[C]\F)\F.[C](=[C]\F)\F.[C](=[C]\F)\F.[C](=[C]\F)\F.[C](=[C]\F)\F.[C](=[C]\F)\F.[C](=O)[O].[C](=O)[O].[O]  str_m1_o1_o2_f0_pcu.sym.6

C(=[CH])([C])O[C]CC.[C](=[CH])OCCC.c12[C]3O[Zn](O[C][C]/C=C(\[C])/OCCC)O[C](c4ccc(C(=O)O[Zn]([O])OC(=O)c5ccc(C(=O)O[Zn]([O])(OC(=O)c6ccc([C](O[Zn@]7(O[C](c(cc1)cc2)O[Zn]([O])O7)O[C][C]/C=[C]/OCCC)O[Zn][O])cc6)[O])cc5)cc4)O[Zn]O[C]([C]/C=[C]/O[C]CC)O[Zn]O3.c12[C]3O[Zn@@](O[C][C]/C=C(\[C])/OCCC)(O[Zn]O3)O[C](c3ccc([C](O[Zn](O[C](c4ccc(C(=O)O[Zn](OC(=O)c5ccc(C(=O)O[Zn@@]([O])(OC(=O)c(cc1)cc2)O[C][C]/C=C(\[C])/OCCC)cc5)[O])cc4)O[Zn])[O])O[Zn])cc3)O[Zn][O].[C]/C=[C]/O[C]CC.[C]/C=C(\[C])/O[C]CC.[C](/C=[C]/O[C]CC)[C].[C](CC)OC(=[CH])[C].C(=[CH])([C])OCCC.[C](CC)OC(=[CH])[C].[C](CC)O[C]=[CH].[C](=[CH])OCCC.[C](=[CH])OCCC.[C]=O.[C](=O)[O].[H].[H].[H].[H].[H].[H].[H].[H].[H].[H].[H].[H].[H].[H].[H].[H]   str_m1_o1_o2_f0_pcu.sym.5

Now, I converted them to .pkl file, but when I tried to load the .pkl file, I get this error:

smi2pkl.py:16 in <module>
    qm9_smiles = pkl.load(f)

UnpicklingError: invalid load key, '['.

Here is the snippet of code I used for the conversion of .smi to .pkl:

with open(out_path, "wb") as f:
    pkl.dump(file_path, f, protocol=pkl.HIGHEST_PROTOCOL) 

Any insight is welcome. Thank you in advance

  • 1
    $\begingroup$ .pkl by itself is not a chemical file format. Instead, it's a general data storage format that Python uses for objects. (Saying you have a pickle of the molecules is like saying you have the molecules in an Excel spreadsheet.) There's no particular benefit in storing SMILES strings in pickle format, rather than plain text listings. You can store molecules/SMILES in pickle format, but how/why to do that is going to depend heavily on your downstream use case. (Which you haven't specified.) $\endgroup$
    – R.M.
    May 8, 2023 at 18:38

2 Answers 2


Say I have a SMI file (smiles.smi) containing these SMILES:


Now lets create a pickle file using the following code:

import pickle

# Open the input SMI file and read its contents
with open('smiles.smi', 'r') as file:
    lines = file.readlines()

# Open the output pickle file and write the list of lines
with open('smiles.pkl', 'wb') as file:
    pickle.dump(lines, file)

Let us now read the pickle file to get back the contents:

with open('smiles.pkl', 'rb') as f:
  smilesList = pickle.load(f)

This will output the contents like:


  • $\begingroup$ Thank you @Vandan for your answer. I tried it but I get this error when I try to run my program: lib/python3.9/site-packages/numpy/lib/format.py", line 741, in read_array raise ValueError("Object arrays cannot be loaded when " ValueError: Object arrays cannot be loaded when allow_pickle=False $\endgroup$ May 7, 2023 at 14:48
  • 1
    $\begingroup$ Please ask a separate question with your entire code, and minimum reproducible example to reproduce your error, along with any required files. Then I can help you out. $\endgroup$ May 7, 2023 at 16:19

From a copy-paste of the two SMILES strings presented e.g. into ChemDraw (a test page, structure -> load SMILES) which not only are separate (hence the joining period in the SMILES string), but symmetry independent.

If you can access COD's codtools (description) which are packaged for Linux Debian/Ubuntu (e.g., Debian's tracker), you can attempt the conversions of the .cif into an .sdf file on the CLI. For example with entry COD 2312069 to redirect the output into an intermediate container file:

$ codcif2sdf 2312069.cif > out.sdf
1 molecule converted

Subsequently, you can represent them as SMILES string e.g., with OpenBabel (GitHub repository, the latest documentation - which equally offers an interface to Python, and can be accessed from the CLI (hence the following equally is accessible to Python's psopen, and subprocess), too e.g. as

$ obabel out.sdf -ocan
Fc1c(F)c(C(=O)[O])c(c(c1F)F)F.O=N(=O)c1ccc(cc1)N1CC[NH2]CC1 2312069
1 molecule converted

or to split it into separate molecules' SMILES by

$ obabel out.sdf -ocan --separate
Fc1c(F)c(C(=O)[O])c(c(c1F)F)F   2312069#1
O=N(=O)c1ccc(cc1)N1CC[NH2]CC1   2312069#2
2 molecules converted

Here, -ocan requests the program to describe the output molecules as canonical SMILES (because the program equally offers universal, and inchified SMILES, too [reference]). Equivalent in result, however yielding a permanent record to the last instruction is

$ obabel out.sdf -ocan --separate -O result.smi
2 molecules converted
$ cat result.smi 
Fc1c(F)c(C(=O)[O])c(c(c1F)F)F   2312069#1
O=N(=O)c1ccc(cc1)N1CC[NH2]CC1   2312069#2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .