#!/usr/bin/env python # coding: utf-8 # # Viewing ase structure using HTML # In[2]: from ase.build import molecule from IPython.display import HTML # In[3]: def atoms_to_html(atoms): 'Return the html representation the atoms object as string' from tempfile import NamedTemporaryFile with NamedTemporaryFile('r+', suffix='.html') as ntf: atoms.write(ntf.name, format='html') ntf.seek(0) html = ntf.read() return html # In[7]: tbut = atoms_to_html(molecule('trans-butane')) HTML(tbut) # In[6]: benzene = atoms_to_html(molecule('C6H6')) HTML(benzene) # # Periodic structure - AFI zeolite # In[13]: aficif ='''data_AFI #************************************************************************** # # CIF taken from the IZA-SC Database of Zeolite Structures # Ch. Baerlocher and L.B. McCusker # Database of Zeolite Structures: http://www.iza-structure.org/databases/ # # The atom coordinates and the cell parameters were optimized with DLS76 # assuming a pure SiO2 composition. # #************************************************************************** _cell_length_a 13.8270(0) _cell_length_b 13.8270(0) _cell_length_c 8.5800(0) _cell_angle_alpha 90.0000(0) _cell_angle_beta 90.0000(0) _cell_angle_gamma 120.0000(0) _symmetry_space_group_name_H-M 'P 6/m c c' _symmetry_Int_Tables_number 192 _symmetry_cell_setting hexagonal loop_ _symmetry_equiv_pos_as_xyz '+x,+y,+z' '-y,+x-y,+z' '-x+y,-x,+z' '-x,-y,+z' '+y,-x+y,+z' '+x-y,+x,+z' '-y,-x,1/2+z' '-x+y,+y,1/2+z' '+x,+x-y,1/2+z' '+y,+x,1/2+z' '+x-y,-y,1/2+z' '-x,-x+y,1/2+z' '-x,-y,-z' '+y,-x+y,-z' '+x-y,+x,-z' '+x,+y,-z' '-y,+x-y,-z' '-x+y,-x,-z' '+y,+x,1/2-z' '+x-y,-y,1/2-z' '-x,-x+y,1/2-z' '-y,-x,1/2-z' '-x+y,+y,1/2-z' '+x,+x-y,1/2-z' loop_ _atom_site_label _atom_site_type_symbol _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z O1 O 0.4565 0.3333 0.0000 O2 O 0.3693 0.3693 0.2500 O3 O 0.4200 0.2100 0.2500 O4 O 0.5798 0.4202 0.2500 T1 Si 0.4565 0.3334 0.1874 ''' # In[14]: def from_string(string, fmt=None): 'Instantiate Atoms object from a string with specific format' import ase.io from tempfile import NamedTemporaryFile with NamedTemporaryFile('r+') as ntf: ntf.write(string) ntf.seek(0) atoms = ase.io.read(ntf, format=fmt) return atoms # In[10]: afi = from_string(aficif, fmt='cif') # In[11]: afi_html = atoms_to_html(afi) # In[12]: HTML(afi_html) # In[7]: get_ipython().run_line_magic('version_information', 'ase, jupyter')