Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assume6columns = True
if sep in line: # Stop at last seperator line
if k == 1:
break
k += 1
if not i > 1:
pass
else:
words = line.split()
if assume6columns is True:
if len(words) != 6:
raise IOError('Number of columns in ACF file incorrect!\n'
'Check that Bader program version >= 0.25')
atom = atoms[int(words[0]) - 1]
atom.charge = atomic_numbers[atom.symbol] - float(words[j])
if displacement is not None: # check if the atom positions match
xyz = np.array([float(w) for w in words[1:4]])
# ACF.dat units could be Bohr or Angstrom
norm1 = np.linalg.norm(atom.position - xyz)
norm2 = np.linalg.norm(atom.position - xyz*Bohr)
assert norm1 < displacement or norm2 < displacement
i += 1
def getMassFromLabel(self, labels):
from ase.data import atomic_masses, atomic_numbers
nums = [atomic_numbers[label] for label in labels]
masses = [atomic_masses[num] for num in nums]
return masses
parameters["kim_interactions"] = "kim_interactions {}{}".format(
(" ").join(supported_species), os.linesep
)
# For every species in "supported_species", add an entry to the
# "masses" key in dictionary "parameters".
parameters["masses"] = []
for i, species in enumerate(supported_species):
if species not in atomic_numbers:
raise KIMCalculatorError(
"Could not determine mass of unknown species "
"{} listed as supported by model".format(species)
)
massstr = str(
convert(
atomic_masses[atomic_numbers[species]],
"mass",
"ASE",
supported_units,
)
)
parameters["masses"].append(str(i + 1) + " " + massstr)
return parameters
key - string corresponding to molecule built by
import_molecules
img_name - filename under which to cache the image
"""
from ase.data import covalent_radii, atomic_numbers
from matplotlib import pyplot, patches
from ase.data.colors import jmol_colors
style = {
"horizontalalignment": "center",
"verticalalignment": "center",
"fontsize": 12
}
fig, ax = pyplot.subplots(1)
for i, p in enumerate(self.positions[key]):
an = atomic_numbers[self.symbols[key][i]]
ax.text(*p[:2],
s=self.labels[key][i],
**style,
zorder=p[-1]+0.01
)
ax.add_artist(patches.Circle(p[:2],
covalent_radii[an],
facecolor=jmol_colors[an],
edgecolor='k',
alpha=0.95,
zorder=p[-1]))
ax.axis('off')
bounds = [*np.min(self.positions[key], axis=0), *
np.max(self.positions[key], axis=0)]
ax.set_xlim([bounds[0]-1.5, bounds[3]+1.5])
ax.set_ylim([bounds[1]-1.5, bounds[5]+1.5])
"""
Returns a cluster with the icosahedra symmetry.
Parameters
----------
symbol: The chemical symbol (or atomic number) of the element.
noshells: The number of shells (>= 1).
latticeconstant (optional): The lattice constant. If not given,
then it is extracted form ase.data.
"""
# Interpret symbol
if isinstance(symbol, basestring):
atomic_number = atomic_numbers[symbol]
else:
atomic_number = symbol
# Interpret noshells
if noshells < 1:
raise ValueError("The number of shells must be equal to or greater than one.")
# Interpret lattice constant
if latticeconstant is None:
if reference_states[atomic_number]['symmetry'] in ['fcc', 'bcc', 'sc']:
lattice_constant = reference_states[atomic_number]['a']
else:
raise NotImplementedError(("Cannot guess lattice constant of a %s element." %
(reference_states[atomic_number]['symmetry'],)))
else:
if isinstance(latticeconstant, (int, float)):
# Number of random initial structures to generate
N = 20
# Target cell volume for the initial structures, in angstrom^3
volume = 240.
# Specify the 'building blocks' from which the initial structures
# will be constructed. Here we take single Ag atoms as building
# blocks, 24 in total.
blocks = [('Ag', 24)]
# We may also write:
blocks = ['Ag'] * 24
# Generate a dictionary with the closest allowed interatomic distances
Z = atomic_numbers['Ag']
blmin = closest_distances_generator(atom_numbers=[Z],
ratio_of_covalent_radii=0.5)
# Specify reasonable bounds on the minimal and maximal
# cell vector lengths (in angstrom) and angles (in degrees)
cellbounds = CellBounds(bounds={'phi': [35, 145], 'chi': [35, 145],
'psi': [35, 145], 'a': [3, 50],
'b': [3, 50], 'c': [3, 50]})
# Choose an (optional) 'cell splitting' scheme which basically
# controls the level of translational symmetry (within the unit
# cell) of the randomly generated structures. Here a 1:1 ratio
# of splitting factors 2 and 1 is used:
splits = {(2,): 1, (1,): 1}
# There will hence be a 50% probability that a candidate
# is constructed by repeating an randomly generated Ag12
representation = get_representation(args, train_loader)
# build output module
if args.model == "schnet":
output_module = spk.atomistic.output_modules.Atomwise(
args.features,
aggregation_mode=args.aggregation_mode,
mean=mean[args.property],
stddev=stddev[args.property],
atomref=atomref[args.property],
property=args.property,
derivative="forces",
negative_dr=True,
)
elif args.model == "wascf":
elements = frozenset((atomic_numbers[i] for i in sorted(args.elements)))
output_module = ElementalAtomwise(
representation.n_symfuncs,
n_hidden=args.n_nodes,
n_layers=args.n_layers,
mean=mean[args.property],
stddev=stddev[args.property],
atomref=atomref[args.porperty],
derivative="forces",
create_graph=True,
elements=elements,
property=args.property,
)
else:
raise NotImplementedError
float(row.charge))
if id is None:
q = self.default + ', ' + ', '.join('?' * len(values))
cur.execute('INSERT INTO systems VALUES ({})'.format(q),
values)
id = self.get_last_id(cur)
else:
q = ', '.join(name + '=?' for name in self.columnnames[1:])
cur.execute('UPDATE systems SET {} WHERE id=?'.format(q),
values + (id,))
if not self.type == 'postgresql':
count = row.count_atoms()
if count:
species = [(atomic_numbers[symbol], n, id)
for symbol, n in count.items()]
cur.executemany('INSERT INTO species VALUES (?, ?, ?)',
species)
text_key_values = []
number_key_values = []
for key, value in key_value_pairs.items():
if isinstance(value, (numbers.Real, np.bool_)):
number_key_values.append([key, float(value), id])
else:
assert isinstance(value, basestring)
text_key_values.append([key, value, id])
cur.executemany('INSERT INTO text_key_values VALUES (?, ?, ?)',
text_key_values)
cur.executemany('INSERT INTO number_key_values VALUES (?, ?, ?)',
def getMassFromLabel(labels):
from ase.data import atomic_masses, atomic_numbers
nums = [atomic_numbers[label] for label in labels]
masses = [atomic_masses[num] for num in nums]
return masses
# structure_list[i].conventional_cell)
poscar = open(dir_name + '/UCell_' + str(i + 1) + '_' + get_spg_n(structure_list[i].space_group) + '.vasp',
'w')
poscar.write(structure_list[i].space_group + '\n' + '1.0\n')
for v in structure_list[i].conventional_cell.cell:
poscar.write('{:>13.7f}{:>13.7f}{:>13.7f}\n'.format(v[0], v[1], v[2]))
# atomic_n = []
ele_n = ''
count_e={}
for j in structure_list[i].conventional_cell.numbers:
if j in count_e:
count_e[j]+=1
else:
count_e[j]=1
for n in count_e.keys():
for key in atomic_numbers.keys():
if atomic_numbers[key]==n:
symbol=key
break
poscar.write('{:4}'.format(symbol))
ele_n += ' {:>3}'.format(count_e[n])
# for symbol in structure_list[i].conventional_cell.symbols.formula._count.keys():
# poscar.write('{:4}'.format(symbol))
# ele_n += ' {:>3}'.format(structure_list[i].conventional_cell.symbols.formula._count[symbol])
poscar.write('\n' + ele_n)
# for symbol in chemical_symbols:
# poscar.write('{:4}'.format(symbol))
# atomic_n.append(atomic_numbers[symbol])
# frequency = 0
# for n in structure_list[i].conventional_cell.numbers:
# if n == atomic_n[-1]: