From: <ate...@us...> - 2006-05-10 19:29:56
|
Revision: 105 Author: atenderholt Date: 2006-05-10 12:29:45 -0700 (Wed, 10 May 2006) ViewCVS: http://svn.sourceforge.net/cclib/?rev=105&view=rev Log Message: ----------- Working on adding calculation methods to cclib. Yeah, yeah, it probably doesn't run yet but it shouldn't break anything. Added Paths: ----------- trunk/src/cclib/methods/ trunk/src/cclib/methods/calculationmethod.py trunk/src/cclib/methods/density.py Added: trunk/src/cclib/methods/calculationmethod.py =================================================================== --- trunk/src/cclib/methods/calculationmethod.py (rev 0) +++ trunk/src/cclib/methods/calculationmethod.py 2006-05-10 19:29:45 UTC (rev 105) @@ -0,0 +1,52 @@ +""" +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 logging, sys +import Numeric + +class Method(object): + """Abstract class for logfile objects. + + Subclasses: + Density + + Attributes: + """ + def __init__(self,parser,progress=None, + loglevel=logging.INFO,logname="Log"): + """Initialise the Logfile object. + + Typically called by subclasses in their own __init__ methods. + """ + self.parser = parser + self.progress = progress + self.loglevel = loglevel + self.logname = logname + + # Set up the logger + self.logger = logging.getLogger('%s %s' % (self.logname,self.parser)) + self.logger.setLevel(self.loglevel) + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter(logging.Formatter("[%(name)s %(levelname)s] %(message)s")) + self.logger.addHandler(handler) + + +if __name__=="__main__": + import doctest,calculationmethod + doctest.testmod(calculationmethod,verbose=False) Property changes on: trunk/src/cclib/methods/calculationmethod.py ___________________________________________________________________ Name: svn:executable + * Added: trunk/src/cclib/methods/density.py =================================================================== --- trunk/src/cclib/methods/density.py (rev 0) +++ trunk/src/cclib/methods/density.py 2006-05-10 19:29:45 UTC (rev 105) @@ -0,0 +1,72 @@ +""" +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 Density(Method): + """Calculate the density matrix""" + def __init__(self,*args): + + # Call the __init__ method of the superclass + super(Density, self).__init__(logname="Density",*args) + + def __str__(self): + """Return a string representation of the object.""" + return "Density matrix of" % (self.parser) + + def __repr__(self): + """Return a representation of the object.""" + return 'Density matrix("%s")' % (self.parser) + + def calculate(self,fupdate=0.05,cupdate=0.002): + """Calculate the density matrix given the results of a parser""" + + if not self.parser.parsed: + self.parser.parse() + + #do we have the needed info in the parser? + if not hasattr(self.parser,"mocoeffs") + and not hasattr(self.parser,"aooverlaps") + and not hasattr(self.parser,"nbasis") + and not hasattr(self.parser,"homos"): + self.logger.error("Missing mocoeffs or aooverlaps") + return False #let the caller of function know we didn't finish + + self.logger.info("Creating attribute density: array[3]") + size=self.parser.nbasis + beta=(len(self.parser.mocoeffs)==2) + + if beta: + self.density=Numeric.zeros([2,size,size],"f") + else: + self.density=Numeric.zeros([1,size,size],"f") + + for i in range(self.parser.homos[0]+1): + col=Numeric.reshape(self.parser.mocoeffs[0][i],(size,1)) + colt=Numeric.reshape(col,(1,size)) + + tempdensity=Numeric.matrixmultipy(col,colt) + density[0]=Numeric.add(density[0],tempdensity) + +if __name__=="__main__": + import doctest,g03parser + doctest.testmod(g03parser,verbose=False) Property changes on: trunk/src/cclib/methods/density.py ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |