Dear all,
The following code:
______________________________________
from rdkit import Chem
import os
import tempfile
# create temp .sdf file with a benzene molecule inside
m1 = Chem.MolFromSmiles('c1ccccc1')
m1.SetProp('_Name', 'benzene')
tempfn = tempfile.mktemp('.sdf')
writer = Chem.SDWriter(tempfn)
writer.write(m1)
writer.close()
# read the molecule from temp .sdf file and print compound name
reader = Chem.SDMolSupplier(tempfn)
m2 = reader[0]
print(m2.GetProp('_Name'))
# unlik temp file
os.unlink(tempfn)
______________________________________
running it in windows gives:
benzene
Traceback (most recent call last):
File "rdclose.py", line 21, in <module>
os.unlink(tempfn)
PermissionError: [WinError 32] The process cannot access the file
because it is being used by another process:
'C:\\Users\\jmn\\AppData\\Local\\Temp\\tmpojn1j4nb.sdf'
I suspect the reason is that reader file is not closed.
Trying reader.close() results in a message saying that reader has no
close() method.
Thank you in advance for helping me to get rid of the temp file.
Take care,
Jean-Marc Nuzillard
--
Jean-Marc Nuzillard
Directeur de Recherches au CNRS
Institut de Chimie Moléculaire de Reims
CNRS UMR 7312
Moulin de la Housse
CPCBAI, Bâtiment 18
BP 1039
51687 REIMS Cedex 2
France
Tel : 03 26 91 82 10
Fax : 03 26 91 31 66
http://www.univ-reims.fr/icmr
http://eos.univ-reims.fr/LSD/CSNteam.html
http://www.univ-reims.fr/LSD/
http://www.univ-reims.fr/LSD/JmnSoft/
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss