Thank you you both! After “dwinston” modify the code, it work well for me except the final one:
first_result = results[0]
mol_id = first_result[‘task_id’]
print(“ID: {}”.format(mol_id))
# Get all data by default
molecule = get_molecule(mol_id)
print(“There are {} key/value pairs in molecule {}. Have a look around!”.format(len(molecule), mol_id))
# The SVG format provides a two-dimensional “pretty picture” of the molecular structure.
svg_of_molecule = get_molecule(mol_id, fmt=‘svg’)
with open(‘molecule.svg’,‘w’) as f:
** f.write(svg_of_molecule)**
** print(“scalable vector graphic saved”)**
# The XYZ representation provided is the optimized geometry of the molecule in a charge-neutral state.
xyz_of_molecule = get_molecule(mol_id, fmt=‘xyz’)
with open(‘molecule.xyz’,‘w’) as f:
** f.write(xyz_of_molecule)**
** print(“XYZ file saved. Can load into molecule-viewer software.”)**
with the following output error:
ID: mol-64060
There are 29 key/value pairs in molecule mol-64060. Have a look around!
TypeError Traceback (most recent call last)
in ()
10 svg_of_molecule = get_molecule(mol_id, fmt=‘svg’)
11 with open(‘molecule.svg’,‘w’) as f:
—> 12 f.write(svg_of_molecule)
13 print(“scalable vector graphic saved”)
14
TypeError: write() argument must be str, not bytes
I have changed the two lines:
open(‘molecule.svg’,‘w’) into open(‘molecule.svg’,‘wb’)
and open(‘molecule.xyz’,‘w’) into open(‘molecule.xyz’,‘wb’)
The old error is sold but I got another error:
NameError Traceback (most recent call last)
in ()
----> 1 first_result = results[0]
2 mol_id = first_result[‘task_id’]
3 print(“ID: {}”.format(mol_id))
4
5 # Get all data by default
NameError: name ‘results’ is not defined
Therefore, in my notebook homepage I saw an empty “molecule.svg” file. I don’t know is this due to Python 3 or not. Please help!