Skip to content

Instantly share code, notes, and snippets.

@ExpHP
Created August 15, 2017 16:54
Show Gist options
  • Select an option

  • Save ExpHP/0fd2e2d3b0d5e74b9d2de9fb8d834255 to your computer and use it in GitHub Desktop.

Select an option

Save ExpHP/0fd2e2d3b0d5e74b9d2de9fb8d834255 to your computer and use it in GitHub Desktop.
gsv instrumented
def _get_equivalent_smallest_vectors_simple(frac_vector,
reduced_bases,
symprec):
def get_lattice_points():
return np.array([
[i, j, k] for i in (-1, 0, 1)
for j in (-1, 0, 1)
for k in (-1, 0, 1)
])
lattice_points = get_lattice_points()
def do_addition():
return frac_vector + lattice_points
candidates = do_addition()
def do_squares():
return np.dot(candidates, reduced_bases)**2
squares = do_squares()
def do_sums():
return np.sum(squares, axis=1)
norm_sqs = do_sums()
def do_roots():
return np.sqrt(norm_sqs)
lengths = do_roots()
def filtered():
return candidates[lengths - lengths.min() < symprec]
return filtered()
def _get_smallest_vectors(supercell, primitive, symprec):
p2s_map, size_super, size_prim, shortest_vectors, multiplicity = [None]*5
reduced_bases, reduced_bases_inv, primitive_lattice, primitive_lattice_inv = [None]*4
supercell_fracs = None
supercell_to_primitive_frac = None
def prep():
...
# omitted: initialization for all of the above
...
prep()
for s_index, s_pos in enumerate(supercell_fracs): # run in supercell
for j, p_index in enumerate(p2s_map): # run in primitive
p_pos = supercell_fracs[p_index]
vectors = _get_equivalent_smallest_vectors_simple(s_pos - p_pos,
reduced_bases,
symprec)
def fill_it():
nonlocal vectors
vectors = [np.dot(v, supercell_to_primitive_frac) for v in vectors]
multiplicity[s_index][j] = len(vectors)
for k, elem in enumerate(vectors):
shortest_vectors[s_index][j][k] = elem
fill_it()
return shortest_vectors, multiplicity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment