Ejemplo n.º 1
0
    def getCostPerNeighbor(self, lowerTime, upperTime):
        sentPerRecipient = []
        for node in self.itervalues():
            sentPerRecipient.extend(node.getCostPerNeighbor(lowerTime,upperTime))

        # Find max and min
        maxNgh = -1
        minNgh = sys.maxint
        for i in sentPerRecipient:
            if(i > maxNgh):
                maxNgh = i                
            if(i < minNgh):
                minNgh = i
        if(len(sentPerRecipient) == 0):
            return -1,-1,-1,-1
        elif(len(sentPerRecipient) == 1):
            return sentPerRecipient[0],0,sentPerRecipient[0],sentPerRecipient[0]
        else:
            return average(sentPerRecipient), standardDeviation(sentPerRecipient),minNgh,maxNgh
Ejemplo n.º 2
0
def MC2(l,f,err,edge,lowl,highl,reps):
    """Monte-carlo method, creates datasets by applying the variance in the
    data to the best-fit model. reps is the number of runs to make"""
    global output
    auto_edge(l,f,err,edge,lowl,highl) #get best-fit
    lne,fne,ene = get_edge(l,f,err,edge,lowl,highl)
    spectrum = results[0][2] * (lne/l_edge)**results[0][0] * N.where(lne>l_edge,1,\
            N.exp(-(lne/l_edge)**3*sig*results[0][1]))
    goodpoints = where(ene<9)
    sd = standardDeviation(fne[goodpoints] - spectrum[goodpoints])
    print "Standard deviation of residuals:",sd
    output = zeros(reps)*1.0
    indeces = zeros(reps)*1.0 #if you want to store both parameters
    for count in range(reps):
        if count%100 == 0 : print count
        fnew = spectrum + randn(len(spectrum))*sd
        output[count] = auto_edge(lne,fnew,ene,edge,lowl,highl)
        indeces[count] = results[0][0] #you want indeces?
    return output,indeces #you want indeces?
Ejemplo n.º 3
0
np = universe.numberOfPoints()
P = np/natoms

#if (rotskipval < 100.0):
#    rotskipratio=1.0
#else:
#    rotskipratio=100.0/rotskipval

# Print averages of the quantu energy estimator
print "Number of Atoms:", natoms
print "Number of Beads:", P
print "Number of Steps:", npoints
#data = trajectory.temperature
#print "Temperature:", mean(data), "+/-",  standardDeviation(data)/sqrt(npoints), " kj/mol"
data = trajectory.quantum_energy_primitive
print "Primitive estimator:", mean(data/Units.k_B), "+/-",  standardDeviation(data/Units.k_B)/sqrt(npoints), " K"
data2 = trajectory.potential_energy

pot_eng = mean(data2/Units.k_B)
pot_eng_error = standardDeviation(data2/Units.k_B)/sqrt(npoints)

print "Potential estimator:", pot_eng, "+/-", pot_eng_error, " K"
print "Kinetic estimator:", mean(data-data2)/Units.k_B
#data = trajectory.kinetic_energy
#print "Kinetic estimator:", mean(data/Units.k_B), "+/-",  standardDeviation(data/Units.k_B)/sqrt(npoints), " K"
#data = trajectory.spring_energy
#print "Spring estimator:", mean(data/Units.k_B), "+/-",  standardDeviation(data/Units.k_B)/sqrt(npoints), " K"

#data = trajectory.quantum_energy_virial
#print "Virial estimator:", mean(data), "+/-",  standardDeviation(data)/sqrt(npoints), " kj/mol"
#data = trajectory.quantum_energy_centroid_virial
traj = argv[1]
trajectory = Trajectory(None, traj)
npoints = len(trajectory)
universe = trajectory.universe
natoms = universe.numberOfAtoms()
time=trajectory.time
np = universe.numberOfPoints()
P = np/natoms

# Print averages of the quantu energy estimator
print "Number of Atoms:", natoms
print "Number of Beads:", P
print "Number of Steps:", npoints

Temp = trajectory.temperature
Eprim = trajectory.quantum_energy_primitive
Ecenv = trajectory.quantum_energy_centroid_virial
Epot = trajectory.potential_energy
Erot = trajectory.quantum_energy_rotation

print "Temperature:", mean(Temp), "+/-",  standardDeviation(Temp)/sqrt(npoints), " K"
print "Primitive estimator:", mean(Eprim/Units.k_B), "+/-",  standardDeviation(Eprim/Units.k_B)/sqrt(npoints), " K"
print "Centroid Virial estimator:", mean(Ecenv/Units.k_B), "+/-", standardDeviation(Ecenv/Units.k_B)/sqrt(npoints), " K"
print "Potential estimator:", mean(Epot/Units.k_B), "+/-",  standardDeviation(Epot/Units.k_B)/sqrt(npoints), " K"
print "Kinetic estimator:",mean(Eprim-Epot)/Units.k_B, "+/-", standardDeviation(Eprim/Units.k_B)/sqrt(npoints)-standardDeviation(Epot/Units.k_B)/sqrt(npoints), " K"
print "Rotational Energy estimator:", mean(Erot/Units.k_B), "+/-",  standardDeviation(Erot/Units.k_B)/sqrt(npoints), " K"
print "Total Energy:", mean(Eprim+Erot)/Units.k_B, "+/-", sqrt((standardDeviation(Eprim)/Units.k_B/sqrt(npoints))**2+(standardDeviation(Erot)/Units.k_B/sqrt(npoints))**2), " K"

trajectory.close()
Ejemplo n.º 5
0
Eprim = trajectory.quantum_energy_primitive
Ecenv = trajectory.quantum_energy_centroid_virial
Epot = trajectory.potential_energy
Erot = trajectory.quantum_energy_rotation

#print "Temperature:", mean(Temp), "+/-",  standardDeviation(Temp)/sqrt(npoints), " K"
#print "Primitive estimator:", mean(Eprim/Units.k_B), "+/-",  standardDeviation(Eprim/Units.k_B)/sqrt(npoints), " K"
#print "Centroid Virial estimator:", mean(Ecenv/Units.k_B), "+/-", standardDeviation(Ecenv/Units.k_B)/sqrt(npoints), " K"

#print "Potential estimator:", mean(Eprim)/Units.k_B, "+/-",  standardDeviation(Eprim)/Units.k_B, " K"
##print "Potential estimator:", mean(Epot/Units.k_B), "+/-",  standardDeviation(Epot/Units.k_B)/sqrt(npoints), " K"
#print "Kinetic estimator:",mean(Ecenv)/Units.k_B, "+/-", standardDeviation(Ecenv)/Units.k_B, " K"
##print "Kinetic estimator:",mean(Eprim-Epot)/Units.k_B, "+/-", standardDeviation(Eprim/Units.k_B)/sqrt(npoints)-standardDeviation(Epot/Units.k_B)/sqrt(npoints), " K"
#print "Rotational Energy estimator:", mean(Erot)/Units.k_B, "+/-",  standardDeviation(Erot)/Units.k_B, " K"
#
#print "Total Energy:", mean(Eprim)/Units.k_B+mean(Erot)/Units.k_B, "+/-", sqrt((standardDeviation(Eprim)/Units.k_B)**2+(standardDeviation(Erot)/Units.k_B)**2), " K"

print "Potential estimator:", mean(Eprim), "+/-", standardDeviation(
    Eprim), " kj/mol"
#print "Potential estimator:", mean(Epot/Units.k_B), "+/-",  standardDeviation(Epot/Units.k_B)/sqrt(npoints), " K"
print "Kinetic estimator:", mean(Ecenv), "+/-", standardDeviation(
    Ecenv), " kj/mol"
#print "Kinetic estimator:",mean(Eprim-Epot)/Units.k_B, "+/-", standardDeviation(Eprim/Units.k_B)/sqrt(npoints)-standardDeviation(Epot/Units.k_B)/sqrt(npoints), " K"
print "Rotational Energy estimator:", mean(Erot), "+/-", standardDeviation(
    Erot), " kj/mol"

print "Total Energy:", mean(Eprim) + mean(Erot), "+/-", sqrt(
    (standardDeviation(Eprim))**2 + (standardDeviation(Erot))**2), " kj/mol"

trajectory.close()
Ejemplo n.º 6
0
    def __init__(self, master, mode_projector, indices):
        from Scientific.Statistics import mean, standardDeviation
        title = "Normal mode projections (Temperature: %5.1f K)" \
                % mode_projector.temperature
        PlotWindow.__init__(self, master, title)
        self.mode_projector = mode_projector

        plot_range = 0.
        for i in indices:
            series = mode_projector[i][:, 1]
            average = mean(series)
            deviation = standardDeviation(series)
            lower = Numeric.minimum.reduce(series)
            lower = min(lower, average-deviation)
            upper = Numeric.maximum.reduce(series)
            upper = max(upper, average+deviation)
            lower, upper = plotRange(lower, upper)
            plot_range = max(plot_range, upper-lower)

        nmodes = mode_projector.numberOfModes()
        for i in range(len(indices)):
            if indices[i] < 0:
                indices[i] = nmodes+indices[i]
        next_indices = []
        step = indices[1] - indices[0]
        i = indices[-1]
        while len(next_indices) < 4:
            i = i + step
            if i >= nmodes:
                break
            next_indices.append(i)
        previous_indices = []
        i = indices[0]
        while len(previous_indices) < 4:
            i = i - step
            if i < 6:
                break
            previous_indices.insert(0, i)
        if next_indices or previous_indices:
            frame = Frame(self)
            frame.pack(side=BOTTOM, fill=X, expand=YES)
            if previous_indices:
                Button(frame, text="Previous",
                       command=lambda s=self, pi=previous_indices:
                               s.modeProjection(pi)).pack(side=LEFT)
            if next_indices:
                Button(frame, text="Next",
                       command=lambda s=self, ni=next_indices:
                               s.modeProjection(ni)).pack(side=RIGHT)

        for i in range(len(indices)):
            number = indices[i]
            data = mode_projector[number]
            fluctuation = self.mode_projector.amplitude(number)
            average = mean(data[:, 1])
            deviation = standardDeviation(data[:, 1])
            box = Frame(self, border=2, relief=SUNKEN)
            box.pack(side=TOP, fill=BOTH, expand=YES)
            frame = Frame(box, background='grey')
            frame.pack(side=TOP, fill=X, expand=NO)
            Label(frame, text="Mode %d" % number,
                  background='grey').pack(side=LEFT)
            Button(frame, text="Animation", background='grey',
                   command=lambda s=self, n=number:
                                  s.animateMode(n, 1.)).pack(side=RIGHT)
            Button(frame, text="View", background='grey',
                   command=lambda s=self, n=number:
                                  s.viewMode(n)).pack(side=RIGHT)
            minv = Numeric.minimum.reduce(data[:,1])
            maxv = Numeric.maximum.reduce(data[:,1])
            minv, maxv = plotRange(minv, maxv)
            middle = 0.5*(maxv+minv)
            if maxv-minv < plot_range:
                minv = middle-0.5*plot_range
                maxv = middle+0.5*plot_range
            plot_objects = [PolyLine([(data[1, 0], average-fluctuation),
                                      (data[1, 0], average+fluctuation)],
                                     color='blue', width=3),
                            PolyLine([(data[-1, 0], average-deviation),
                                      (data[-1, 0], average+deviation)],
                                     color='green', width=3)]
            plot_objects.insert(0, PolyLine(data, color = 'red'))
            plot = PlotCanvas(box, 400, 100, zoom=1,
                              select=self.master._selectRange)
            plot.pack(side=LEFT, fill=BOTH, expand=YES)
            plot.draw(PlotGraphics(plot_objects), 'automatic', (minv, maxv))
            plot.bind('<Double-Button-1>', lambda event, d=data:
                                           externalPlot(d))
            self.registerPlot(plot)
            self.setSelection(plot)
Ejemplo n.º 7
0
    def __init__(self, master, mode_projector, indices):
        from Scientific.Statistics import mean, standardDeviation
        title = "Normal mode projections (Temperature: %5.1f K)" \
                % mode_projector.temperature
        PlotWindow.__init__(self, master, title)
        self.mode_projector = mode_projector

        plot_range = 0.
        for i in indices:
            series = mode_projector[i][:, 1]
            average = mean(series)
            deviation = standardDeviation(series)
            lower = Numeric.minimum.reduce(series)
            lower = min(lower, average - deviation)
            upper = Numeric.maximum.reduce(series)
            upper = max(upper, average + deviation)
            lower, upper = plotRange(lower, upper)
            plot_range = max(plot_range, upper - lower)

        nmodes = mode_projector.numberOfModes()
        for i in range(len(indices)):
            if indices[i] < 0:
                indices[i] = nmodes + indices[i]
        next_indices = []
        step = indices[1] - indices[0]
        i = indices[-1]
        while len(next_indices) < 4:
            i = i + step
            if i >= nmodes:
                break
            next_indices.append(i)
        previous_indices = []
        i = indices[0]
        while len(previous_indices) < 4:
            i = i - step
            if i < 6:
                break
            previous_indices.insert(0, i)
        if next_indices or previous_indices:
            frame = Frame(self)
            frame.pack(side=BOTTOM, fill=X, expand=YES)
            if previous_indices:
                Button(frame,
                       text="Previous",
                       command=lambda s=self, pi=previous_indices: s.
                       modeProjection(pi)).pack(side=LEFT)
            if next_indices:
                Button(frame,
                       text="Next",
                       command=lambda s=self, ni=next_indices: s.
                       modeProjection(ni)).pack(side=RIGHT)

        for i in range(len(indices)):
            number = indices[i]
            data = mode_projector[number]
            fluctuation = self.mode_projector.amplitude(number)
            average = mean(data[:, 1])
            deviation = standardDeviation(data[:, 1])
            box = Frame(self, border=2, relief=SUNKEN)
            box.pack(side=TOP, fill=BOTH, expand=YES)
            frame = Frame(box, background='grey')
            frame.pack(side=TOP, fill=X, expand=NO)
            Label(frame, text="Mode %d" % number,
                  background='grey').pack(side=LEFT)
            Button(frame,
                   text="Animation",
                   background='grey',
                   command=lambda s=self, n=number: s.animateMode(n, 1.)).pack(
                       side=RIGHT)
            Button(frame,
                   text="View",
                   background='grey',
                   command=lambda s=self, n=number: s.viewMode(n)).pack(
                       side=RIGHT)
            minv = Numeric.minimum.reduce(data[:, 1])
            maxv = Numeric.maximum.reduce(data[:, 1])
            minv, maxv = plotRange(minv, maxv)
            middle = 0.5 * (maxv + minv)
            if maxv - minv < plot_range:
                minv = middle - 0.5 * plot_range
                maxv = middle + 0.5 * plot_range
            plot_objects = [
                PolyLine([(data[1, 0], average - fluctuation),
                          (data[1, 0], average + fluctuation)],
                         color='blue',
                         width=3),
                PolyLine([(data[-1, 0], average - deviation),
                          (data[-1, 0], average + deviation)],
                         color='green',
                         width=3)
            ]
            plot_objects.insert(0, PolyLine(data, color='red'))
            plot = PlotCanvas(box,
                              400,
                              100,
                              zoom=1,
                              select=self.master._selectRange)
            plot.pack(side=LEFT, fill=BOTH, expand=YES)
            plot.draw(PlotGraphics(plot_objects), 'automatic', (minv, maxv))
            plot.bind('<Double-Button-1>',
                      lambda event, d=data: externalPlot(d))
            self.registerPlot(plot)
            self.setSelection(plot)