def num_wann_from_projections(projections: List[Dict[str, Any]], atoms: Atoms): # Works out the value of 'num_wann' based on the 'projections' block num_wann = 0 for proj in projections: if 'site' in proj: if len(set(atoms.get_tags())) > 0: labels = [s + str(t) if t != 0 else s for s, t in zip(atoms.symbols, atoms.get_tags())] else: labels = [s for s in atoms.symbols] num_sites = labels.count(proj['site']) else: num_sites = 1 ang_mtms = [p.replace(' ', '') for p in proj['ang_mtm'].split(';')] num_wann += num_sites * sum([num_wann_lookup(ang_mtm) for ang_mtm in ang_mtms]) return num_wann
def run(argv=None): if argv is None: argv = sys.argv[1:] elif isinstance(argv, str): argv = argv.split() parser = build_parser() opt, args = parser.parse_args(argv) if len(args) != 1: parser.error("incorrect number of arguments") name = args[0] if world.rank == 0: out = sys.stdout#open('%s-%s.results' % (name, opt.identifier), 'w') else: out = devnull a = None try: symbols = string2symbols(name) except ValueError: # name was not a chemical formula - must be a file name: atoms = read(name) else: if opt.crystal_structure: a = opt.lattice_constant if a is None: a = estimate_lattice_constant(name, opt.crystal_structure, opt.c_over_a) out.write('Using an estimated lattice constant of %.3f Ang\n' % a) atoms = bulk(name, opt.crystal_structure, a, covera=opt.c_over_a, orthorhombic=opt.orthorhombic, cubic=opt.cubic) else: try: # Molecule? atoms = molecule(name) except NotImplementedError: if len(symbols) == 1: # Atom atoms = Atoms(name) elif len(symbols) == 2: # Dimer atoms = Atoms(name, positions=[(0, 0, 0), (opt.bond_length, 0, 0)]) else: raise ValueError('Unknown molecule: ' + name) if opt.magnetic_moment: magmom = opt.magnetic_moment.split(',') atoms.set_initial_magnetic_moments(np.tile(magmom, len(atoms) // len(magmom))) if opt.repeat is not None: r = opt.repeat.split(',') if len(r) == 1: r = 3 * r atoms = atoms.repeat([int(c) for c in r]) if opt.gui: view(atoms) return if opt.write_to_file: write(opt.write_to_file, atoms) return if opt.effective_medium_theory: Runner = EMTRunner else: Runner = GPAWRunner if opt.fit: strains = np.linspace(0.98, 1.02, 5) else: strains = None if opt.constrain_tags: tags = [int(t) for t in opt.constrain_tags.split(',')] constrain = FixAtoms(mask=[t in tags for t in atoms.get_tags()]) atoms.constraints = [constrain] runner = Runner(name, atoms, strains, tag=opt.identifier, clean=not opt.read, fmax=opt.relax, out=out) if not opt.effective_medium_theory: # Import stuff that eval() may need to know: from gpaw.wavefunctions.pw import PW from gpaw.occupations import FermiDirac, MethfesselPaxton if opt.parameters: input_parameters = eval(open(opt.parameters).read()) else: input_parameters = {} for key in defaults: value = getattr(opt, key) if value is not None: try: input_parameters[key] = eval(value) except (NameError, SyntaxError): input_parameters[key] = value runner.set_parameters(vacuum=opt.vacuum, write_gpw_file=opt.write_gpw_file, **input_parameters) runner.run() runner.summary(plot=opt.plot, a0=a) return runner