From: <ate...@us...> - 2006-05-19 17:30:13
|
Revision: 130 Author: atenderholt Date: 2006-05-19 10:29:54 -0700 (Fri, 19 May 2006) ViewCVS: http://svn.sourceforge.net/cclib/?rev=130&view=rev Log Message: ----------- Reworked cspa to use base population class, haven't tested because my cclib parser installation seems to be broken. Committing since it's not a high-profile change. Modified Paths: -------------- trunk/src/cclib/method/cspa.py Added Paths: ----------- trunk/src/cclib/method/population.py Modified: trunk/src/cclib/method/cspa.py =================================================================== --- trunk/src/cclib/method/cspa.py 2006-05-19 16:37:32 UTC (rev 129) +++ trunk/src/cclib/method/cspa.py 2006-05-19 17:29:54 UTC (rev 130) @@ -20,14 +20,14 @@ import re,time import Numeric import random # For sometimes running the progress updater -from calculationmethod import Method +from population import Population -class CSPA(Method): +class CSPA(Population): """The C-squared population analysis""" def __init__(self,*args): # Call the __init__ method of the superclass - super(CSPA, self).__init__(logname="Density",*args) + super(CSPA, self).__init__(logname="CSPA",*args) def __str__(self): """Return a string representation of the object.""" @@ -37,7 +37,7 @@ """Return a representation of the object.""" return 'CSPA("%s")' % (self.parser) - def calculate(self,fupdate=0.05): + def calculate(self,indices=None,fupdate=0.05): """Perform a C-squared population analysis given the results of a parser""" if not self.parser.parsed: @@ -84,75 +84,29 @@ if self.progress: self.progress.update(nstep,"Done") -#build list of groups of orbitals in each atom for atomresults - if hasattr(self.parser,"aonames"): - names=self.parser.aonames - elif hasattr(self.parser,"foonames"): - names=self.parser.fonames + retval=super(CSPA, self).partition(indices) - atoms=[] - indices=[] + if not retval: + self.logger.error("Error in partitioning results") + return False - name=names[0].split('_')[0] - atoms.append(name) - indices.append([0]) - - for i in range(1,len(names)): - name=names[i].split('_')[0] - if name==atoms[-1]: - indices[-1].append(i) - else: - atoms.append(name) - indices.append([i]) - - self.logger.info("Creating atomresults: array[3]") - self.atomresults=self.partition(indices) - #create array for mulliken charges - self.logger.info("Creating atomcharges: array[1]") - size=len(self.atomresults[0][0]) - self.atomcharges=Numeric.zeros([size],"f") + self.logger.info("Creating fragcharges: array[1]") + size=len(self.fragresults[0][0]) + self.fragcharges=Numeric.zeros([size],"f") - for spin in range(len(self.atomresults)): + for spin in range(len(self.fragresults)): for i in range(self.parser.homos[spin]+1): - temp=Numeric.reshape(self.atomresults[spin][i],(size,)) - self.atomcharges=Numeric.add(self.atomcharges,temp) + temp=Numeric.reshape(self.fragresults[spin][i],(size,)) + self.fragcharges=Numeric.add(self.fragcharges,temp) if not unrestricted: - self.atomcharges=Numeric.multiply(self.atomcharges,2) + self.fragcharges=Numeric.multiply(self.fragcharges,2) - return True - def partition(self,indices): - - if not hasattr(self,"aoresults"): - self.calculate() - - natoms=len(indices) - nmocoeffs=len(self.aoresults[0]) - -#build results Numeric array[3] - if len(self.aoresults)==2: - results=Numeric.zeros([2,nmocoeffs,natoms],"f") - else: - results=Numeric.zeros([1,nmocoeffs,natoms],"f") - -#for each spin, splice Numeric array at ao index, and add to correct result row - for spin in range(len(results)): - - for i in range(natoms): #number of groups - - for j in range(len(indices[i])): #for each group - - temp=self.aoresults[spin,:,indices[i][j]] - results[spin,:,i]=Numeric.add(results[spin,:,i],temp) - - return results - - if __name__=="__main__": import doctest,cspa doctest.testmod(cspa,verbose=False) Added: trunk/src/cclib/method/population.py =================================================================== --- trunk/src/cclib/method/population.py (rev 0) +++ trunk/src/cclib/method/population.py 2006-05-19 17:29:54 UTC (rev 130) @@ -0,0 +1,114 @@ +""" +cclib is a parser for computational chemistry log files. + +See http://cclib.sf.net for more information. + +Copyright (C) 2006 Noel O'Boyle and Adam Tenderholt + + This program is free software; you can redistribute and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + +Contributions (monetary as well as code :-) are encouraged. +""" +import re,time +import Numeric +import random # For sometimes running the progress updater +from calculationmethod import Method + +class Population(Method): + """A base class for all population-type methods""" + def __init__(self,*args): + + # Call the __init__ method of the superclass + super(Population, self).__init__(logname="Population",*args) + self.fragresults=None + + def __str__(self): + """Return a string representation of the object.""" + return "Population" + + def __repr__(self): + """Return a representation of the object.""" + return "Population" + + +#create array for mulliken charges + self.logger.info("Creating atomcharges: array[1]") + size=len(self.atomresults[0][0]) + self.atomcharges=Numeric.zeros([size],"f") + + for spin in range(len(self.atomresults)): + + for i in range(self.parser.homos[spin]+1): + + temp=Numeric.reshape(self.atomresults[spin][i],(size,)) + self.atomcharges=Numeric.add(self.atomcharges,temp) + + if not unrestricted: + self.atomcharges=Numeric.multiply(self.atomcharges,2) + + return True + + def partition(self,indices=None): + + if not hasattr(self,"aoresults"): + self.calculate() + + if not indices: +#build list of groups of orbitals in each atom for atomresults + if hasattr(self.parser,"aonames"): + names=self.parser.aonames + elif hasattr(self.parser,"foonames"): + names=self.parser.fonames + + atoms=[] + indices=[] + + name=names[0].split('_')[0] + atoms.append(name) + indices.append([0]) + + for i in range(1,len(names)): + name=names[i].split('_')[0] + try: + index=atoms.index(name) + except ValueError: #not found in atom list + atoms.append(name) + indices.append([i]) + else: + indices[index].append(i) + + natoms=len(indices) + nmocoeffs=len(self.aoresults[0]) + +#build results Numeric array[3] + if len(self.aoresults)==2: + results=Numeric.zeros([2,nmocoeffs,natoms],"f") + else: + results=Numeric.zeros([1,nmocoeffs,natoms],"f") + +#for each spin, splice Numeric array at ao index, and add to correct result row + for spin in range(len(results)): + + for i in range(natoms): #number of groups + + for j in range(len(indices[i])): #for each group + + temp=self.aoresults[spin,:,indices[i][j]] + results[spin,:,i]=Numeric.add(results[spin,:,i],temp) + + self.logger.info("Saving partitioned results in fragresults: array[3]") + self.fragresults=results + + return True + +if __name__=="__main__": + import doctest,mpa + doctest.testmod(mpa,verbose=False) Property changes on: trunk/src/cclib/method/population.py ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |