# FAHProject.py
#
# Daniel L. Ensign
# Pande Group
# Dept. of Chemistry
# Stanford University 
#
# 9/10/07
# 
# This file contains a Python object suitable for representing a Folding@home
# project.
#
"""
Usage:

	project4100 = FAHProject( "/home/server/server2/projects/project4100.conf" )

Implemented features:
- None
 
Features currently in development:
- Read project configuration (using ConfigurationParser)
- Given a structure (gro), add a new RUN to the project in analogy to
  previous RUNs, run SetupDataDirs, and restart. That's several features:
	- add a new RUN to the project in analogy to previous runs
	- run SetupDataDirs (may require manipulation of project.conf)
	- restart server (should maybe be a different object)
"""

from ConfigurationParser import ProjectConfigurationFile
from glob import glob

class FAHProject( object ):

	def __init__ ( self, conffile ):
		self.conffile = conffile
		self.conf = ProjectConfigurationFile( self.conffile )
		
	def countReturnedWUs( self ):
		datapath = self.conf.datapath
		nRuns = self.conf.nruns
		nClones = self.conf.nclones

		nret = 0

		run = 0
		while run < nRuns :
			clone = 0
			while clone < nClones :
				dirname = datapath + "/" + "RUN%d/CLONE%d/" % ( run, clone )
				rc = glob( dirname + "*.xtc" )
				nret += len( rc )
				clone += 1
	
			run += 1
		
		return nret
