#we record the search trip to plot it later.. searchTripGraph[alpha] = delta_I return delta_I #Only needed to plot the loss function (with the found minumum) def plotDifferentRouteFuction(graphAsDict, alpha_min, f_alpha_min): #we must sort the dict since the search trip was a hopping one.. finderFunctionGraph = collections.OrderedDict(sorted(graphAsDict.items())) pl.plot(finderFunctionGraph.keys(), finderFunctionGraph.values(), label = 'Route 1 - Route 2' ); pl.plot(alpha_min, f_alpha_min, 'o', color='red') pl.show() if __name__ == '__main__': solver = ScipyAndersonOZsolver(port = 0) #solver = ScipyNewtonKrylovOZsolver(port = 0) #We only work with LJ or Yukawa potential since we want to avoid the trouble #related to the 'jump' (discontinuity) at r = sigma doLennardJonesExample = False if doLennardJonesExample: #LJ possible but with HMSA solver.setPotentialByName('LennardJones', 0.1) #epsilon/kT = 0.1 is default in SASfit print "Energy scale of Lennard Jones Potential in kT units:", solver.getEpsilonInkTUnits() #Initialize HMSA with some (random) start alpha solver.doHMSAclosure(1.0) else: #Yukawa possible with RY: With negative K (attractive besides HS) convergence may be reached for exp shift only (real HS-Yukawa)
from picardOZsolver import PicardOZsolver from andersonOZsolver import AndersonOZsolver from scipyAndersonOZsolver import ScipyAndersonOZsolver from scipyNewtonKrylovOZsolver import ScipyNewtonKrylovOZsolver if __name__ == '__main__': #Dict to contain the various algorithms (classes) solverClassDictionary = {} #Dict to contain the various results (algorithm specific) algorithmSqDictionary = {} #Instantiate solver classes (port=0 means no server) solverClassDictionary['Picard'] = PicardOZsolver(port=0) solverClassDictionary['Anderson'] = AndersonOZsolver(port=0) solverClassDictionary['scipyAnderson'] = ScipyAndersonOZsolver(port=0) solverClassDictionary['scipyNewtonKrylov'] = ScipyNewtonKrylovOZsolver( port=0) #Basic params, use HardSphere together with analytical Solution (and PY, but this is default) density = 0.3 potential = 'HardSphere' #Start loop over classes (calculate S(q) with all algorithms) for algorithmKey in solverClassDictionary: #Activate the next line to use a different FPO, here the investment in design pays off, #since the fixpoint operator can easily be exchanged without further modifications #solverClassDictionary[algorithmKey].doNotUseGammaFixPointOperator() solverClassDictionary[algorithmKey].setPotentialByName(potential) solverClassDictionary[algorithmKey].setVolumeDensity(density) solverClassDictionary[algorithmKey].solve()
initial search direction is correct. Experiments show that a zero start value may be better than the previous. ''' import numpy as np #Solver from scipyAndersonOZsolver import ScipyAndersonOZsolver #plot import matplotlib.pyplot as plt import pylab as pl if __name__ == '__main__': solver = ScipyAndersonOZsolver(port = 0) solver.setPotentialByName('HardSphere') #solver.setNumberOfIterations(10*solver.getNumberOfIterations()) #Relaxing ConvergenceCriterion by a factor 1000 solver.setConvergenceCriterion(1.0e3*solver.getConvergenceCriterion()) #solver.setPotentialByName('LennardJones', 0.5) startDensity = 0.58 targetDensity = 0.63 totalDeltaDensity = targetDensity - startDensity density = startDensity deltaDensity = totalDeltaDensity decayFactor = 2.5 deltaDensity = 0.01
#Plot results r = solver.getrArray() for potentialType in boltzmannOfPotentialDictionary: pl.plot(r, boltzmannOfPotentialDictionary[potentialType], label='exp(-beta*' + str(potentialType) + ')') pl.xlabel('r/sigma') pl.ylabel('exp(-beta*u)') pl.legend(loc='upper right') pl.show() #We just repeat everything from above with a density > 0 to get a RDF fifferent from the Boltzmann of mutual potential density = 0.3 #We switch to ScipyAndersonOZsolver since it can better handle Star potential (?) solver = ScipyAndersonOZsolver(port=0) solver.setVolumeDensity(density) for potentialType in listOfPotentials: solver.setPotentialByName(*(potentialType.split('_'))) solver.solve() g = solver.getRDF() RDFdictionary[potentialType] = g #Plot results r = solver.getrArray() for potentialType in RDFdictionary: pl.plot(r, RDFdictionary[potentialType], label='RDF with' + str(potentialType)) pl.xlabel('r/sigma') pl.ylabel('g')
#performance measurement import time #Solver from picardOZsolver import PicardOZsolver from andersonOZsolver import AndersonOZsolver from scipyAndersonOZsolver import ScipyAndersonOZsolver from scipyNewtonKrylovOZsolver import ScipyNewtonKrylovOZsolver if __name__ == '__main__': #Instantiate solver class (Picard iteration, etc.) #For star potential, ScipyAndersonOZsolver gives best result #s = PicardOZsolver(port = 0) #s = AndersonOZsolver(port = 0) s = ScipyAndersonOZsolver(port = 0) #s = ScipyNewtonKrylovOZsolver(port = 0) s.printPotentialSetterArguments() #s.setPotentialByName('HardSphere') #s.setPotentialByName('LennardJones', 0.2) s.setPotentialByName('Star', 20) #Define the density range to scan densityRange = np.arange(0.3, 0.4, 0.1) #densityRange = np.asarray([0.3]) #densityRange = np.asarray([0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]) densityRDFdictionary = {} #Start loop over densities and measure wall clock time
options, args = parser.parse_args() return options, args #Start here #******************************************************************************************************************************************************************* if __name__ == '__main__': options, args = readOptions() portNumber = int(options.portNumber) typeOfIteration = options.typeOfIteration if typeOfIteration == 'Picard': PicardOZsolver(portNumber) elif typeOfIteration == 'Anderson': AndersonOZsolver(portNumber) elif typeOfIteration == 'ScipyAnderson': ScipyAndersonOZsolver(portNumber) elif typeOfIteration == 'ScipyNewtonKrylov': ScipyNewtonKrylovOZsolver(portNumber) else: print "Unknown iteration schema, exiting" sys.exit()
For alpha -> 0, PYC is recovered, for alpha -> inf, HNC closure is recovered ''' import numpy as np from scipyAndersonOZsolver import ScipyAndersonOZsolver #plot import matplotlib.pyplot as plt import pylab as pl if __name__ == '__main__': closureRDFdictionary = {} solver = ScipyAndersonOZsolver(port=0) solver.setPotentialByName('HardSphere') solver.setVolumeDensity(0.4) #Default is PY print "PY closure.." solver.solve() closureRDFdictionary['PY'] = solver.getRDF() print "HNC closure.." solver.doHNCclosure() solver.solve() closureRDFdictionary['HNC'] = solver.getRDF() print "RY closure, alpha -> 0.." solver.doRYclosure(alpha=0.0001) #Not exactly zero...
(as expressed in (2) ) does not hold strictly (only on average). So far for the naming) The script calculates the OZ solution of the HS + PY system with and without the S_c(0) result. ''' import numpy as np from scipyAndersonOZsolver import ScipyAndersonOZsolver #plot import matplotlib.pyplot as plt if __name__ == '__main__': solver = ScipyAndersonOZsolver(port = 0) solver.setPotentialByName('HardSphere') volumeDensity = 0.5 solver.setVolumeDensity(volumeDensity) solver.setConvergenceCriterion(1.0e-4*solver.getConvergenceCriterion()) #PY is default, so no explicit settings are needed in this regard #so solver is in desired state. solver.solve() #Get reference structure factor Sq_default = solver.getSq() #now GCE limit version solver.doEnforceGrandCanonicalZeroQlimit() #solver is in desired state. solver.solve() #Get GCE structure factor Sq_GCE = solver.getSq()
and hence particle conservation (as expressed in (2) ) does not hold strictly (only on average). So far for the naming) The script calculates the OZ solution of the HS + PY system with and without the S_c(0) result. ''' import numpy as np from scipyAndersonOZsolver import ScipyAndersonOZsolver #plot import matplotlib.pyplot as plt if __name__ == '__main__': solver = ScipyAndersonOZsolver(port=0) solver.setPotentialByName('HardSphere') volumeDensity = 0.5 solver.setVolumeDensity(volumeDensity) solver.setConvergenceCriterion(1.0e-4 * solver.getConvergenceCriterion()) #PY is default, so no explicit settings are needed in this regard #so solver is in desired state. solver.solve() #Get reference structure factor Sq_default = solver.getSq() #now GCE limit version solver.doEnforceGrandCanonicalZeroQlimit() #solver is in desired state. solver.solve() #Get GCE structure factor Sq_GCE = solver.getSq()
For alpha -> 0, PYC is recovered, for alpha -> inf, HNC closure is recovered ''' import numpy as np from scipyAndersonOZsolver import ScipyAndersonOZsolver #plot import matplotlib.pyplot as plt import pylab as pl if __name__ == '__main__': closureRDFdictionary = {} solver = ScipyAndersonOZsolver(port = 0) solver.setPotentialByName('HardSphere') solver.setVolumeDensity(0.4) #Default is PY print "PY closure.." solver.solve() closureRDFdictionary['PY'] = solver.getRDF() print "HNC closure.." solver.doHNCclosure() solver.solve() closureRDFdictionary['HNC'] = solver.getRDF() print "RY closure, alpha -> 0.." solver.doRYclosure(alpha=0.0001) #Not exactly zero...
#Only needed to plot the loss function (with the found minumum) def plotDifferentRouteFuction(graphAsDict, alpha_min, f_alpha_min): #we must sort the dict since the search trip was a hopping one.. finderFunctionGraph = collections.OrderedDict(sorted(graphAsDict.items())) pl.plot(finderFunctionGraph.keys(), finderFunctionGraph.values(), label='Route 1 - Route 2') pl.plot(alpha_min, f_alpha_min, 'o', color='red') pl.show() if __name__ == '__main__': solver = ScipyAndersonOZsolver(port=0) #solver = ScipyNewtonKrylovOZsolver(port = 0) #We only work with LJ or Yukawa potential since we want to avoid the trouble #related to the 'jump' (discontinuity) at r = sigma doLennardJonesExample = False if doLennardJonesExample: #LJ possible but with HMSA solver.setPotentialByName('LennardJones', 0.1) #epsilon/kT = 0.1 is default in SASfit print "Energy scale of Lennard Jones Potential in kT units:", solver.getEpsilonInkTUnits( ) #Initialize HMSA with some (random) start alpha solver.doHMSAclosure(1.0)