Ok Paulo,
with open(tempfn, 'rb') as reader:
fsuppl = Chem.ForwardSDMolSupplier(reader)
for m2 in fsuppl:
print(m2.GetProp('_Name'))
works fine for what I want to do.
Best,
Jean-Marc
Le 29/03/2020 à 16:35, Jean-Marc Nuzillard a écrit :
Hi Paolo,
neither tempfn (a string)
Hi Paolo,
neither tempfn (a string) nor reader (a SDMolSupplier) have a close()
method.
I am not sure about what you wrote about the "with" statement.
Attempting:
with Chem.SDMolSupplier(tempfn) as reader:
m2 = reader[0]
print(m2.GetProp('_Name'))
resulted in:
with
Hi Jean-Marc,
tempfn.close() should allow you to delete the file.
A better alternative would be using using
with temp file.TemporaryFile as tempfn
...
As the file will be automatically closed and deleted for you as soon as it goes
out of scope at the end of the context manager block.
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('c1c1')
m1.SetProp('_Name', 'benzene')
tempfn = tempfile.mktemp('.sdf')
writer =
4 matches
Mail list logo