httk quickstart
Install
Clone the master branch of the source code repository:
git clone https://github.com/httk/httk
Then, every time you want to use httk, initialize the environtment with:
source /path/to/httk/init.shell
Structures
Load a cif file or poscar
This is a very simple example of just loading a structure from a .cif file and writing out some information about it.
import httk
struct = httk.load("example.cif")
print("Formula:", struct.formula)
print("Volume:", float(struct.uc_volume))
print("Assignments:", struct.uc_formula_symbols)
print("Counts:", struct.uc_counts )
print("Coords:", struct.uc_reduced_coords)
Running this generates the output:
('Formula:', 'BO2Tl')
('Volume', 509.24213999999984)
('Assignments',['B', 'O', 'Tl'])
('Counts:', [8, 16, 8])
('Coords', FracVector(((1350,4550,4250) , ... , ,10000)))
Create structures in code
from httk.atomistic import Structure
cell = [[1.0, 0.0, 0.0] ,
[0.0, 1.0, 0.0] ,
[0.0, 0.0, 1.0]]
coordgroups = [[
[0.5, 0.5, 0.5]
],[
[0.0, 0.0, 0.0]
],[
[0.5, 0.0, 0.0], [0.0, 0.5, 0.0], [0.0, 0.0, 0.5]
]]
assignments = ['Pb' ,'Ti' ,'O']
volume =62.79
struct = Structure.create(uc_cell = cell,
uc_reduced_coordgroups = coordgroups,
assignments = assignments,
uc_volume = volume)
Databases
Create database file, store a structure in it, and retrive it
import httk, httk.db
from httk.atomistic import Structure
backend = httk.db.backend.Sqlite('example.sqlite')
store = httk.db.store.SqlStore(backend)
tablesalt = httk.load('NaCl.cif')
store.save(tablesalt)
arsenic = httk.load('As.cif')
store.save(arsenic)
# Search for anything with Na
search = store.searcher()
search_struct = search.variable(Structure)
search.add(search_struct.formula_symbols.is_in('Na'))
search.output(search_struct, 'structure')
for match, header in list(search):
struct = match[0]
print "Found structure", struct.formula, [str(struct.get_tags()[x]) for x in struct.get_tags()]
Create database file and store your own data in it
#!/usr/bin/env python
import httk, httk.db
from httk.atomistic import Structure
class StructureIsEdible(httk.HttkObject):
@httk.httk_typed_init({'structure': Structure, 'is_edible': bool})
def __init__(self, structure, is_edible):
self.structure = structure
self.is_edible = is_edible
backend = httk.db.backend.Sqlite('example.sqlite')
store = httk.db.store.SqlStore(backend)
tablesalt = httk.load('NaCl.cif')
edible = StructureIsEdible(tablesalt, True)
store.save(edible)
arsenic = httk.load('As.cif')
edible = StructureIsEdible(arsenic, False)
store.save(edible)