Esempio n. 1
0
    def get_RDF(self, cluster, filename, save_to):
        elements = list(set(cluster.get_chemical_symbols()))
        for index in range(len(elements)):
            elements[index] = atomic_numbers[elements[index]]
        element_pairs = []
        for element1 in elements:
            for element2 in elements:
                element_pairs.append((element1, element2))

        RDF_results = {}
        RDFobj = RadialDistributionFunction(cluster,
                                            self.rdf_max_dist,
                                            self.no_of_bins,
                                            verbose=True)
        for element_pair in element_pairs:
            rdf_pair = RDFobj.get_rdf(elements=element_pair)
            element_pair = tuple(sorted(element_pair))
            if not (element_pair in list(RDF_results.keys())):
                RDF_results[element_pair] = rdf_pair
            else:
                RDF_results[element_pair] += rdf_pair

        #plotting
        x_axis = self.rdf_max_dist * np.linspace(
            0, 1, self.no_of_bins, endpoint=True)
        for element_pair, rdf_pair in sorted(RDF_results.items()):
            element_pair_name = ', '.join(
                tuple(chemical_symbols[element] for element in element_pair))
            #rdf_pair = list(rdf_pair)
            plt.plot(x_axis,
                     rdf_pair,
                     color=self.colours[element_pair],
                     label=element_pair_name)

        plt.xlim(self.xlim_RDF)
        plt.legend()
        plt.xlabel('Interatomic distance ' + r'$(\AA)$')
        plt.ylabel('Radial distribution function')
        plt.tight_layout()
        file_path_name = save_to + '/' + filename + "_RDF"
        plt.savefig(file_path_name + ".png")
        plt.savefig(file_path_name + ".eps")
        plt.savefig(file_path_name + ".svg")
        plt.cla()
        plt.clf()
Esempio n. 2
0
def rdf_org_traj(atoms, rng, bins, used_snaps):
    """rdf
    Calculate radial distribution functions:
    measures the probability of finding an atom at distance r given that there
    is an atom at position 0; it is thus essentially a histogram of interatomic
    distances - and is calculated as such

    :param structure: the ASE trajectory file
    :param rng: max distance up to which RDF is calculated, in Ångström
    :param bins: number of bins used for histogram, i.e. resolution of the RDF
    :param used_snaps: the number of used snapshots from the trajectory file
    :return rdf vector: values of the RDF
    """
    # truncation of trajectory
    trunc_traj = []
    for i in range(len(atoms)):
        trunc_traj.append(atoms[i])

    # Determine RDF
    RDFobj = None
    for atoms in trunc_traj:
        if RDFobj is None:
            RDFobj = RadialDistributionFunction(atoms, rng, bins)
        else:
            RDFobj.atoms = atoms  # Fool RDFobj to use the new atoms
        RDFobj.update()  # Collect data
    # obtain RDF
    rdf = RDFobj.get_rdf()
    return rdf
Esempio n. 3
0
def rdf(atoms, rng, bins):
    """rdf
    Calculate radial distribution functions:
    measures the probability of finding an atom at distance r given that there
    is an atom at position 0; it is thus essentially a histogram of interatomic
    distances - and is calculated as such

    :param structure: the atoms object being analyzed
    :param rng: max distance up to which RDF is calculated, in Ångström
    :param bins: number of bins used for histogram, i.e. resolution of the RDF
    :return n_generations: the number of generations
    :return rdf vector: values of the RDF
    """
    # number of generations
    n_generations = len(atoms)
    # initialize trajectory object
    new_structure = []

    for i in range(n_generations):
        new_structure.append(
            Atoms(symbols='Si30', pbc=True, cell=[10.0, 10.0,
                                                  10.0]))  # initialize objects
        new_structure[i].set_positions(atoms[i])
    # Determine RDF
    RDFobj = None
    for atoms in new_structure:
        if RDFobj is None:
            RDFobj = RadialDistributionFunction(atoms, rng, bins)
        else:
            RDFobj.atoms = atoms  # Fool RDFobj to use the new atoms
        RDFobj.update()  # Collect data
    # obtain RDF
    rdf = RDFobj.get_rdf()
    return n_generations, rdf
Esempio n. 4
0
    def calculate_rdf(self, traj_file, r_max=10.0, nbins=100):
        traj = read(traj_file, ":")

        x = (np.arange(nbins) + 0.5) * r_max / nbins
        rdf_obj = None
        for atoms in traj:
            if rdf_obj is None:
                rdf_obj = RadialDistributionFunction(atoms, r_max, nbins)
            else:
                rdf_obj.atoms = atoms
            rdf_obj.update()
        rdf = rdf_obj.get_rdf()

        return x, rdf
Esempio n. 5
0
    def rdf_vec(self, data):
        """Return list of partial rdfs for use as fingerprint vector."""
        if not no_asap:
            rf = RadialDistributionFunction(data,
                                            rMax=self.rmax,
                                            nBins=self.nbin).get_rdf
            kwargs = {}
        else:
            rf = get_rdf
            dm = self.get_all_distances(data)
            kwargs = {
                'atoms': data,
                'rmax': self.rmax,
                'nbins': self.nbin,
                'no_dists': True,
                'distance_matrix': dm
            }

        fp = []
        for c in product(set(data.numbers), repeat=2):
            fp.extend(rf(elements=c, **kwargs))

        return fp
Esempio n. 6
0
def get_RDF(
    alist,
    rcut,
    nBin=500,
    symbol_tuple=None,
    log=False,
):
    from asap3.analysis.rdf import RadialDistributionFunction as RDF
    RDFobj = RDF(
        atoms=alist[0],
        rMax=rcut,
        nBins=nBin,
    )
    for i in range(1, len(alist)):
        RDFobj.atoms = alist[i]
        RDFobj.update()
        if log and i % 1000 == 999:
            print('\t Updating ' + str(i + 1) + " th image's RDF")

    ## Total RDF
    if symbol_tuple == ('a', 'a'):
        rdf = RDFobj.get_rdf()
    ## Partial RDF
    else:
        # Get normalize constant
        (unique, counts) = np.unique(alist[0].get_chemical_symbols(),
                                     return_counts=True)
        norm_const = counts[list(unique).index(symbol_tuple[1])] / np.sum(
            counts, dtype=np.float)
        #
        from chemical_symbol_number_inverter import invert_chem_sym_num
        spec_inds = invert_chem_sym_num(symbol_tuple)
        #
        rdf = RDFobj.get_rdf(elements=tuple(spec_inds)) / norm_const
    x = np.arange(nBin) / float(nBin) * rcut
    ## Return curve
    return np.transpose(np.concatenate(([x], [rdf])))
Esempio n. 7
0
iniatoms.set_calculator(EMT())
inidyn = Langevin(iniatoms, 5*units.fs, 450*units.kB, 0.05)
inidyn.run(100)
print "Temperature is now", iniatoms.get_kinetic_energy() / (1.5*units.kB*len(iniatoms)), "K"

print "Making reference simulation"
refatoms = Atoms(iniatoms)
refatoms.set_calculator(EMT())
dyn = VelocityVerlet(refatoms, 5*units.fs)
ref = []
for i in range(50):
    dyn.run(5)
    epot = refatoms.get_potential_energy() / len(refatoms)
    ekin = refatoms.get_kinetic_energy() / len(refatoms)
    ref.append([epot, ekin, epot+ekin])

ref = array(ref)

print "Testing RestrictedCNA"
atoms = Atoms(iniatoms)
atoms.set_calculator(EMT())
cna = RestrictedCNA(atoms)
Compare("RestrictedCNA", atoms, cna.analyze, ref)

print "Testing RadialDistributionFunction"
atoms = Atoms(iniatoms)
atoms.set_calculator(EMT())
rdf = RadialDistributionFunction(atoms, 4.0, 25)
Compare("RadialDistributionFunction", atoms, rdf.update, ref)

Esempio n. 8
0
traj = []
trunc_traj = []

for i in range(n_snaps):
    atoms = load_trajectory(trajs[i])
    trunc_traj.append(atoms[0])
    atoms.close()

# Setup RDF out to a distance of X Rng, with Y bins
rng = 6.0
bins = 100

# Calculating the RDF of a previously stored trajectory
# https://wiki.fysik.dtu.dk/asap/Radial%20Distribution%20Functions
RDFobj = None
for atoms in trunc_traj:
    if RDFobj is None:
        RDFobj = RadialDistributionFunction(atoms, rng, bins)
    else:
        RDFobj.atoms = atoms  # Fool RDFobj to use the new atoms
    RDFobj.update()  # Collect data

rdf = RDFobj.get_rdf()

# Get the RDF and plot it.
rdf = RDFobj.get_rdf()
x = np.arange(bins) * rng / bins
plt.plot(x, rdf)
plt.show()
Esempio n. 9
0
# Create a block of Cu atoms, expand the crystal 10% to leave space
# for thermal expansion and to facilitate melting.  Describe
# interactions with EMT, and set a very high initial temperature so it
# melts.
atoms = L1_2(size=(20,20,20), symbol=("Au", "Cu"), pbc=True,
             latticeconstant=3.75)

atoms.set_calculator(EMT())
MaxwellBoltzmannDistribution(atoms, 600*units.kB)

# First, run 25 time steps before taking data.
dyn = VelocityVerlet(atoms, 5*units.fs, logfile='-')
dyn.run(25)

# Make the RDF object, attach it to the dynamics
RDFobj = RadialDistributionFunction(atoms, rng, bins, verbose=True)
dyn.attach(RDFobj.update, interval=5)

# Run the simulation
dyn.run(100)

# Get the RDF and plot it.
rdf = RDFobj.get_rdf()
x = np.arange(bins) * rng / bins
plt.plot(x, rdf, 'k')  # Black

# Get the partial RDFs and plot them
Au = data.atomic_numbers['Au']
Cu = data.atomic_numbers['Cu']
rdfAuAu = RDFobj.get_rdf(elements=(Au, Au))
plt.plot(x, rdfAuAu, 'r')
Esempio n. 10
0
             (3.7, 6.001, 100, True),
             (3.6, 15.001, 100, False),
             (3.65, 15.001, 100, True))

for latconst, maxrdf, nbins, withemt in testtypes:

    atoms = FaceCenteredCubic(directions=[[1,0,0],[0,1,0],[0,0,1]], symbol="Cu",
                              size=(10,10,10), latticeconstant=latconst)
    natoms = len(atoms)
    ReportTest("Number of atoms", natoms, 4000, 0)

    if withemt:
        atoms.set_calculator(EMT())
        print atoms.get_potential_energy()

    rdf = RadialDistributionFunction(atoms, maxrdf, nbins)
    z = atoms.get_atomic_numbers()[0]

    globalrdf = rdf.get_rdf()
    localrdf = rdf.get_rdf(elements=(z,z))

    print globalrdf

    ReportTest("Local and global RDF are identical",
               max(abs(globalrdf - localrdf)), 0.0, 1e-6)
        
    shellpop = [12, 6, 24, 12, 24, -1]
    shell = [sqrt(i+1.0)/sqrt(2.0) for i in range(6)]
    print shell
    print shellpop
    n = 0
Esempio n. 11
0
File: RDF.py Progetto: auag92/n2dm
# We want RDF out to a distance of 15 Angstrom, with 200 bins
rng=15.0
bins = 200

# Create a block of Cu atoms, expand the crystal 10% to leave space
# for thermal expansion and to facilitate melting.  Describe
# interactions with EMT, and set a very high initial temperature so it
# melts.
atoms = FaceCenteredCubic(size=(20,20,20), symbol="Cu", pbc=True)
atoms.set_cell(atoms.get_cell() * 1.1, scale_atoms=True)

atoms.set_calculator(EMT())
MaxwellBoltzmannDistribution(atoms, 3500*units.kB)

# First, run 25 time steps before taking data.
dyn = VelocityVerlet(atoms, 4*units.fs, logfile='-')
dyn.run(25)

# Make the RDF object, attach it to the dynamics
RDFobj = RadialDistributionFunction(atoms, rng, bins, verbose=True)
dyn.attach(RDFobj.update, interval=5)

# Run the simulation
dyn.run(100)

# Get the RDF and plot it.
rdf = RDFobj.get_rdf()
x = np.arange(bins) * rng / bins
plt.plot(x, rdf)
plt.show()
traj = read(sys.argv[1], index='0:200')
traj_og = read(sys.argv[2], index='0:200')

rMax = 15.0
nBins = 1000
x = np.linspace(0, rMax, nBins)
bar = progressbar.ProgressBar()

fig, ax = plt.subplots(1, 1, figsize=(20, 10))

RDFobj = None
for atoms in bar(traj):
    atoms.cell = [400, 400, 400]
    if RDFobj is None:
        RDFobj = RadialDistributionFunction(atoms, rMax, nBins)
    else:
        RDFobj.atoms = atoms  # Fool RDFobj to use the new atoms
    RDFobj.update()  # Collect data
rdf_PP = RDFobj.get_rdf(elements=(15, 15))
rdf_PN = RDFobj.get_rdf(elements=(15, 7))
rdf_NN = RDFobj.get_rdf(elements=(7, 7))

bar = progressbar.ProgressBar()
RDFobj = None
for atoms in bar(traj_og):
    atoms.cell = [400, 400, 400]
    if RDFobj is None:
        RDFobj = RadialDistributionFunction(atoms, rMax, nBins)
    else:
        RDFobj.atoms = atoms  # Fool RDFobj to use the new atoms
Esempio n. 13
0
             (5.15, 15.001, 100, True, False)
             )

for latconst, maxrdf, nbins, withemt, save in testtypes:

    atoms = NaCl(directions=[[1,0,0],[0,1,0],[0,0,1]],
                 symbol=("Cu", "Au"), size=(10,10,10),
                 latticeconstant=latconst, debug=0)
    natoms = len(atoms)
    ReportTest("Number of atoms", natoms, 8000, 0)

    if withemt:
        atoms.set_calculator(EMT())
        print atoms.get_potential_energy()

    rdf = RadialDistributionFunction(atoms, maxrdf, nbins)
    if save:
        rdf.output_file("RDF2-rdf")
    z = atoms.get_atomic_numbers()[0]

    globalrdf = rdf.get_rdf()
    localrdf = zeros(globalrdf.shape, float)
    for i in (29,79):
        for j in (29,79):
            localrdf += rdf.get_rdf(elements=(i,j))

    ReportTest("Local and global RDF are identical",
               min( globalrdf == localrdf), 1, 0)
        
    shellpop = [6, 12, 8, 6, 24, -1]
    shell = [sqrt(i+1.0)/2.0 for i in range(6)]