Return a unit cell for a slab of 110
 specify the number of atomic monolayers
 and the vacuum thickness in angstrom
489507
def get_110_surface(monolayers, vacuum=0, constrain_layers = 0)

      # The atoms on a FCC 
      atom1 = Atom.new(0,0,0,self.cation)
      atom2 = Atom.new(self.lattice_const*1/(2*sqrt(2)), self.lattice_const*0.25, 0.0, self.anion)

      # The lattice Vectors
      v1 = Vector[1/sqrt(2), 0.0, 0.0]*self.lattice_const
      v2 = Vector[0.0, 1.0, 0.0]*self.lattice_const
      v3 = Vector[1/(2*sqrt(2)), -0.5, 1/(2*sqrt(2))]*self.lattice_const

      # The miller indices for each primitive cartesian direction
      millerX = Vector[1, -1, 0]
      millerY = Vector[0, 0, 1]
      millerZ = Vector[1, 1, 0]

      # The unit cell
      zb = Geometry.new([atom1, atom2], [v1, v2, v3])
      zb.set_miller_indices(millerX, millerY, millerZ)

      # Repeat the unit cell
      zb = zb.repeat(1,1,monolayers)


      monolayerSep = v3[2]
      if 0 < vacuum
        # Add vacuum
        zb.lattice_vectors[2] = Vector[0, 0, (monolayers-1)*monolayerSep.abs + vacuum.to_f]
        # Move everything into a nice tidy unit cell. 
        zb = zb.correct
      end

      # # Constrain the bottom layers
      zb.atoms.each{|a|
        if (a.z < monolayerSep*constrain_layers)
          a.constrain = ".true."
        end
      }

      
      # Return the completed unit cell
      return zb
    end
30807
private int getOthers(IMolecularFormula formula) {
        int number = 0;
        String[] elements = {"Co", "Hg", "Pt", "As"};
        for (int i = 0; i < elements.length; i++)
            number += MolecularFormulaManipulator.getElementCount(formula,
                    formula.getBuilder().newInstance(IElement.class, elements[i]));

        return number;
    }
615585
def determine_coefficient
      # Array of photon energies (in units of MeV).
      @energies = [
        0.001,
        0.0015,
        0.002,
        0.003,
        0.004,
        0.005,
        0.006,
        0.008,
        0.01,
        0.015,
        0.02,
        0.03,
        0.04,
        0.05,
        0.06,
        0.08,
        0.1,
        0.15,
        0.2,
        0.3,
        0.4,
        0.5,
        0.6,
        0.8,
        1.0,
        1.25,
        1.5,
        2.0,
        3.0,
        4.0,
        5.0,
        6.0,
        8.0,
        10.0,
        15.0,
        20.0
      ]
      # Array of mass attenuation coefficients for the above energies, for liquid water (in units of cm^2/g):
      @att_coeffs = [
        4078,
        1376,
        617.3,
        192.9,
        82.78,
        42.58,
        24.64,
        10.37,
        5.329,
        1.673,
        0.8096,
        0.3756,
        0.2683,
        0.2269,
        0.2059,
        0.1837,
        0.1707,
        0.1505,
        0.137,
        0.1186,
        0.1061,
        0.09687,
        0.08956,
        0.07865,
        0.07072,
        0.06323,
        0.05754,
        0.04942,
        0.03969,
        0.03403,
        0.03031,
        0.0277,
        0.02429,
        0.02219,
        0.01941,
        0.01813
      ]
      # Determine the coefficient:
      if @energy >= 20.0
        # When the energy is above 20, we use the coefficient for 20 MeV:
        @ac_water = @att_coeffs.last
      else
        if i = @energies.index(@energy)
          # When it exactly matches one of the listed energies, use its corresponding coefficient:
          @ac_water = @att_coeffs[i]
        else
          # When the given energy is between two of the listed values, interpolate:
          i_after = @energies.index {|x| x > @energy}
          if i_after
            e_high = @energies[i_after]
            e_low = @energies[i_after - 1]
            ac_high = @att_coeffs[i_after]
            ac_low = @att_coeffs[i_after - 1]
            @ac_water = (ac_high - ac_low ) / (e_high - e_low) * (@energy - e_low)
          else
            raise "Unexpected behaviour with index in the energy interpolation logic."
          end
        end
      end
    end
666799
def calcMassFromMz(mz, charge):
    
    mass = (mz - maspy.constants.atomicMassProton) * charge
    return mass
1154333
def get_monolayer(self):
        

        unit_a = self.get_unit_primitive_area
        Nsurfs = self.Nsurfs_ads_in_slab
        Nads = self.Nads_in_slab
        return Nads / (unit_a * Nsurfs)
482241
def operator_si(u):
    """"""
    global _aux
    if np.ndim(u) == 2:
        P = _P2
    elif np.ndim(u) == 3:
        P = _P3
    else:
        raise ValueError("u has an invalid number of dimensions "
                         "(should be 2 or 3)")
    
    if u.shape != _aux.shape[1:]:
        _aux = np.zeros((len(P),) + u.shape)
    
    for _aux_i, P_i in zip(_aux, P):
        _aux_i[:] = binary_erosion(u, P_i)
    
    return _aux.max(0)
1175515
def refine_cell(self, tilde_obj):
        '''
        
        '''
        try: lattice, positions, numbers = spg.refine_cell(tilde_obj['structures'][-1], symprec=self.accuracy, angle_tolerance=self.angle_tolerance)
        except Exception as ex:
            self.error = 'Symmetry finder error: %s' % ex
        else:
            self.refinedcell = Atoms(numbers=numbers, cell=lattice, scaled_positions=positions, pbc=tilde_obj['structures'][-1].get_pbc())
            self.refinedcell.periodicity = sum(self.refinedcell.get_pbc())
            self.refinedcell.dims = abs(det(tilde_obj['structures'][-1].cell))
925797
private int element(IAtom atom) {
        Integer element = atom.getAtomicNumber();
        if (element != null) return element;
        if (atom instanceof IPseudoAtom) return 0;
        throw new IllegalArgumentException("Aromaiticty model requires atomic numbers to be set");
    }
36369
def sample(self, wavelength):
        """"""
        wave = self.waveunits.Convert(wavelength, 'angstrom')
        return self(wave)
917422
def _set_lattice(self):
        

        unit = self._values[0]
        if unit == 'alat':
            if not self._tags['celldm(1)']:
                print("celldm(1) has to be specified when using alat.")
                sys.exit(1)
            else:
                factor = self._tags['celldm(1)']  # in Bohr
        elif unit == 'angstrom':
            factor = 1.0 / Bohr
        else:
            factor = 1.0

        if len(self._values[1:]) < 9:
            print("CELL_PARAMETERS is wrongly set.")
            sys.exit(1)

        lattice = np.reshape([float(x) for x in self._values[1:10]], (3, 3))
        self._tags['cell_parameters'] = lattice * factor
654880
private int getOxygenCount(IAtomContainer ac, IAtom atom) {
        List<IAtom> neighbours = ac.getConnectedAtomsList(atom);
        int ocounter = 0;
        for (IAtom neighbour : neighbours) {
            if (neighbour.getSymbol().equals("O")) {
                if (!neighbour.getFlag(CDKConstants.ISAROMATIC)) {
                    ocounter += 1;
                }
            }
        }
        return ocounter;
    }
603626
def create_slab_label(self):
        

        if "label" in self.data.keys():
            return self.data["label"]

        label = str(self.miller_index)
        ads_strs = list(self.ads_entries_dict.keys())

        cleaned = self.cleaned_up_slab
        label += " %s" % (cleaned.composition.reduced_composition)

        if self.adsorbates:
            for ads in ads_strs:
                label += r"+%s" % (ads)
            label += r", %.3f ML" % (self.get_monolayer)
        return label
607658
def get_cp2k_structure(atoms):
    """"""

    from cp2k_tools.generator import dict2cp2k

    # CP2K's default unit is angstrom, convert it, but still declare it explictly:
    cp2k_cell = {sym: ('[angstrom]',) + tuple(coords) for sym, coords in zip(('a', 'b', 'c'), atoms.get_cell()*Bohr)}
    cp2k_cell['periodic'] = 'XYZ'  # anything else does not make much sense
    cp2k_coord = {
        'scaled': True,
        '*': [[sym] + list(coord) for sym, coord in zip(atoms.get_chemical_symbols(), atoms.get_scaled_positions())],
        }

    return dict2cp2k(
        {
            'global': {
                'run_type': 'ENERGY_FORCE',
                },
            'force_eval': {
                'subsys': {
                    'cell': cp2k_cell,
                    'coord': cp2k_coord,
                    },
                'print': {
                    'forces': {
                        'filename': 'forces',
                        },
                    },
                },
            }
        )
1267122
private int getAtomPosition(IAtom atom, IAtomContainer container) {
        for (int i = 0; i < container.getAtomCount(); i++) {
            if (atom.equals(container.getAtom(i))) {
                return i;
            }
        }
        return -1;
    }
194041
private double getDensity(Atom[] ca1subset, Atom[] ca2subset ) throws StructureException{

		Atom centroid1 =  Calc.getCentroid(ca1subset);
		Atom centroid2 = Calc.getCentroid(ca2subset);

		// get Average distance to centroid ...

		double d1 = 0;
		double d2 = 0;

		for ( int i = 0 ; i < ca1subset.length;i++){
			double dd1 = Calc.getDistance(centroid1, ca1subset[i]);
			double dd2 = Calc.getDistance(centroid2, ca2subset[i]);

			d1 += dd1;
			d2 += dd2;

		}

		double avd1 = d1 / ca1subset.length;
		double avd2 = d2 / ca2subset.length;

		return Math.min(avd1,avd2);
	}
933589
def get_vecang_cell(cryst, uc=None):
    '''
    
    '''
    if uc is None:
        uc = cryst.get_cell()
    ucv = [uc[i, :]/norm(uc[i, :]) for i in range(3)]
    uca = [acos(dot(ucv[(i+1) % 3], ucv[(i+2) % 3])) for i in range(3)]
    return [norm(uc[i, :]) for i in range(3)] + uca
328003
def mw(mol, ndigits=2):
    
    mol.require("Valence")
    return round(sum(a.mw() for _, a in mol.atoms_iter()), ndigits)