Implement search_by_formula and search_by_mass
Opened this issue · 6 comments
Hi- I was wondering if it's possible to search_by_mass
and search_by_formula
as stated in the documentation? I get an error when I try to follow the documentation. I am using ChemSpiPy==2.0.0
.
>>> cs.search_by_mass(680, 0.001)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'ChemSpider' object has no attribute 'search_by_mass'
>>> cs.search_by_formula('C44H30N4Zn')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'ChemSpider' object has no attribute 'search_by_formula'
>>>
This issue makes me think that it hasn't been implemented yet.
Thanks!
Yeah, I didn't manage to add these before the 2.0.0 release. It is on the 'To Do list' for the next release, when I get some time.
Here's a rough idea of how you could implement it yourself:
def search_by_mass(mass, mass_range, datasources=None, order=None, direction=None):
qid = cs.filter_mass(mass, mass_range, datasources, order, direction)
while True:
status = cs.filter_status(qid)
if status['status'] == 'Complete':
csids = cs.filter_results(qid)
compounds = [objects.Compound(cs, csid) for csid in csids]
return compounds
elif status['status'] in {'Failed', 'Unknown', 'Suspended', 'Not Found'}:
raise Exception('Error searching by mass')
Thanks very much for the quick reply!!!!!!!!
Seems to have worked when in an interactive python session when I from chemspipy import objects
.
Hi,
I am also using this, do you know how we can search by formula?
When I search:
for result in cs.search("C6H6"):
print(result.record_id)
I get no results, but when I type Benzene it comes up? Is there any reason for this?