示例#1
0
def dgdxi(i, node, atom_coords, excl_inds,
          control=control, coord=coord,
          eps=eps, srun=srun_command, dscf=dscf_command,
          grad=grad_command): 
    if node.occupied is None:
        node.occupied = i
    # wait
    while(node.occupied != i):
        if node.occupied is None:
	   node.occupied = i
        yield (False, None)
    # wait
    while(node.update_status() != Node.IDLE):
        yield (False, None)
    my_coord   = node.node_dir+'/'+coord
    my_control = node.node_dir+'/'+control
    node.restore_files()
    # wait
    while(node.update_status() != Node.IDLE):
        yield (False, None)
    changed = update_coord(i, eps, atom_coords, my_coord)
    print "node {} coord {} dscf+".format(node.node_dir, i)
    node.run(srun + dscf)
    while(node.update_status() != Node.IDLE):
        yield (False, None)
    print "node {} coord {} grad+".format(node.node_dir, i)
    node.run(srun + grad)
    # wait
    while(node.update_status() != Node.IDLE):
        yield (False, None)
    grads, en = read_control(my_control, changed)
    print "{}-th + Energy {}".format(i,en)
    res = exclude_grads_and_flatten(grads, excl_inds)
    node.make_log(out_files=(coord, control), prefix='task_p')
    node.restore_files()
    update_coord(i, -eps, atom_coords, my_coord)
    print "node {} coord {} dscf-".format(node.node_dir, i)
    node.run(srun + dscf)
    # wait
    while(node.update_status() != Node.IDLE):
        yield (False, None)
    print "node {} coord {} grad-".format(node.node_dir, i)
    node.run(srun + grad)
    # wait
    while(node.update_status() != Node.IDLE):
        yield (False, None)
    grads, en = read_control(my_control, changed)
    print "{}-th - Energy {}".format(i, en)
    node.make_log(out_files=(coord, control), prefix='task_m')
    res = res - exclude_grads_and_flatten(grads,
                                          excl_inds)
    res = res/(2*eps)
    node.occupied = None
    yield (True, (res, p_res))
示例#2
0
    def run_atm(self):
        """ Program sequence """
        #====================================================
        # Initialization Process
        #====================================================
        print '==================='
        print ' Initializing ATM'
        print '==================='
        read_control.read_control(self)
        initialize.initialize(self)
        read_layers.read_layers(self)
        model_domain.model_domain(self)
        create_attm_cohort_arrays.create_attm_cohort_arrays(self)

        #=========================================
        # Initializing Site Specific Information
        #=========================================
        if self.Simulation_area.lower() == 'barrow':
            run_barrow.initialize_barrow(self)
        elif self.Simulation_area.lower() == 'tanana':
            run_tanana.initialize_tanana(self)
        elif self.Simulation_area.lower() == 'yukon':
            run_yukon.initialize_yukon(self)

        #=======================================
        # READ MET Data, Calculate Degree Days,
        # and Calculate Climatic Data needed
        # for ecotype changes.
        #=======================================
        initialize.Met(self)

        #++++++++++++++++++++++++++++++++++++++++++++++
        #  ========================================
        #    INITIALIZE COHORT PROPERTIES
        #  ========================================
        #++++++++++++++++++++++++++++++++++++++++++++++
        print '======================================'
        print ' Initializing Terrestrial Properties '
        print '======================================'
        if self.Simulation_area.lower() == 'barrow':
            run_barrow.initialize_barrow_cohorts(self)
        elif self.Simulation_area.lower() == 'tanana':
            run_tanana.Terrestrial_Tanana(self)

        print '=================================================='
        print '            Starting the MAIN LOOP '
        print '=================================================='

        initialize.run(self)
        if self.Simulation_area.lower() == 'barrow':
            run_barrow.run_barrow(self, time)
        elif self.Simulation_area.lower() == 'tanana':
            run_tanana.run_tanana(self, time)

        print '=================================================='
        print '            Finished the MAIN LOOP '
        print '=================================================='

        # -------------------
        # Simulation End Time
        # -------------------
        clock.finish(self)

        #===========================
        # Output Simulation Results
        #===========================
        if self.results_onscreen.lower() == 'yes':
            results.on_screen(self)
        if self.archive_simulation.lower() == 'yes':
            results.on_file(self)

        # ================
        # Archive Results
        # ================
        if self.archive_simulation.lower() == 'yes':
            archive.read_archive(self)
            archive.archive(self)
            #----------------------------------------------------------------------------------------------------------
            # Create the tarfile
            #----------------------------------------------------------------------------------------------------------
            self.archive_file =tarfile.open(self.control['Run_dir']+self.Output_directory+str('/Archive/')+ \
                                            self.archive_time+str('_')+self.simulation_name+".tar.gz", mode='w:gz')
            #----------------------------------------------------------------------------------------------------------
            if self.Simulation_area.lower() == 'barrow':
                os.chdir(self.control['Run_dir'] + self.Input_directory +
                         '/Barrow/')

        print '----------------------------------------'
        print '        Simulation Complete             '
        print '----------------------------------------'
示例#3
0
import sys
sys.path.insert(0,"./modules")
from read_control import read_control
from read_rmc6f import read_rmc6f
from j2j0_calc import j2j0_calc

try:
    contr_file = sys.argv[1]
except:
    print "Usage: python mc_main.py CONTROL_FILE_NAME"
    sys.exit(0)

print "------------------------------------------------------------------------>"
print "First, we read in the main control file.\n"
config_name,j2j0Min,j2j0Max,j2j0binNum,EFermi,out_file,j2j0WinAnalysis,j2j0WinMin,\
	j2j0WinMax,rbinsNum,distHistOutFile = read_control(contr_file)
print "<------------------------------------------------------------------------\n"

print "------------------------------------------------------------------------>"
print "Next, we proceed to read in the structure configuration.\n"
metric,atomList = read_rmc6f(config_name)
print "<------------------------------------------------------------------------\n"

print "------------------------------------------------------------------------>"
print "Next, we move to the main body of the J/J0 statistics calculation.\n"
if j2j0WinAnalysis=="T":
	print "J/J0 window analysis will be carried out.\n"
	j2j0Out,rbinsOut = j2j0_calc(j2j0Min,j2j0Max,j2j0binNum,EFermi,metric,\
		atomList,j2j0WinAnalysis,j2j0WinMin,j2j0WinMax,rbinsNum)
else:
	j2j0Out = j2j0_calc(j2j0Min,j2j0Max,j2j0binNum,EFermi,metric,atomList,\
示例#4
0
文件: ATM.py 项目: ua-snap/atm
    def run_atm(self):
        
        """ Program sequence """
        #====================================================
        # Initialization Process
        #====================================================
        print '==================='
        print ' Initializing ATM'
        print '==================='
        read_control.read_control(self)
        initialize.initialize(self)
        read_layers.read_layers(self)
        model_domain.model_domain(self)
        create_attm_cohort_arrays.create_attm_cohort_arrays(self)


        #=========================================
        # Initializing Site Specific Information
        #=========================================
        if self.Simulation_area.lower() == 'barrow':
            run_barrow.initialize_barrow(self)
        elif self.Simulation_area.lower() == 'tanana':
            run_tanana.initialize_tanana(self)
         
        #=======================================
        # READ MET Data, Calculate Degree Days,
        # and Calculate Climatic Data needed
        # for ecotype changes.
        #=======================================
        initialize.Met(self)

        #++++++++++++++++++++++++++++++++++++++++++++++
        #  ========================================
        #    INITIALIZE COHORT PROPERTIES
        #  ========================================
        #++++++++++++++++++++++++++++++++++++++++++++++
    	print '======================================'
        print ' Initializing Terrestrial Properties '
        print '======================================'
        if self.Simulation_area.lower() == 'barrow':
            run_barrow.initialize_barrow_cohorts(self)
        elif self.Simulation_area.lower() == 'tanana':
            run_tanana.Terrestrial_Tanana(self)

        print '=================================================='
        print '            Starting the MAIN LOOP '
        print '=================================================='

        initialize.run(self)
        if self.Simulation_area.lower() == 'barrow':
            run_barrow.run_barrow(self, time)
	elif self.Simulation_area.lower() == 'tanana':
	    run_tanana.run_tanana(self, time)

        print '=================================================='
        print '            Finished the MAIN LOOP '
        print '=================================================='


        # -------------------
        # Simulation End Time
        # -------------------
        clock.finish(self)
        
        #===========================
        # Output Simulation Results
        #===========================
        if self.results_onscreen.lower() == 'yes':
            results.on_screen(self)
        if self.archive_simulation.lower() == 'yes':
            results.on_file(self)

        
        # ================
        # Archive Results
        # ================
        if self.archive_simulation.lower() == 'yes':
        #----------------------------------------------------------------------------------------------------------
        # Create the tarfile
        #----------------------------------------------------------------------------------------------------------
            self.archive_file =tarfile.open(self.control['Run_dir']+self.Output_directory+str('/Archive/')+ \
                                            self.archive_time+str('_')+self.simulation_name+".tar.gz", mode='w:gz')
        #----------------------------------------------------------------------------------------------------------
            archive.read_archive(self)
            archive.archive(self)
            
        print '----------------------------------------'
        print '        Simulation Complete             '
        print '----------------------------------------'        
示例#5
0
    def run_attm(self):
        
        """ Program sequence """
        #====================================================
        # Initialization Process
        #====================================================
        print '==================='
        print ' Initializing ATTM'
        print '==================='
        read_control.read_control(self)
        initialize.initialize(self)
        read_layers.read_layers(self)
        model_domain.model_domain(self)
        create_attm_cohort_arrays.create_attm_cohort_arrays(self)
        if self.Simulation_area.lower() == 'barrow':
            initial_cohort_population.barrow_initial_cohort_population(self)
            initial_cohort_check.barrow_initial_cohort_check(self)
            cohort_present.barrow_cohort_present(self)
        elif self.Simulation_area.lower() == 'tanana':
            initial_cohort_population.tanana_initial_cohort_population(self)
            initial_cohort_check.tanana_initial_cohort_check(self)
            cohort_present.tanana_cohort_present(self)

         
        #=======================================
        # READ MET Data & Calculate Degree Days
        #=======================================
        initialize.Met(self)


        #++++++++++++++++++++++++++++++++++++++++++++++
        #  ========================================
        #    INITIALIZE BARROW COHORT PROPERTIES
        #  ========================================
        #++++++++++++++++++++++++++++++++++++++++++++++
        if self.Simulation_area.lower() == 'barrow':
            print '=================================== '
            print ' Initializing Lake & Pond Properties'
            print '===================================='
            initialize.LakePond(self)
            set_lake_pond_depth.set_lake_pond_depth(self)
            set_lake_ice_depth_constant.set_lake_ice_depth_constant(self)
            set_ice_thickness_array.set_ice_thickness_array(self)
            climate_expansion_arrays.set_climate_expansion_arrays(self)
            set_pond_growth_array.set_pond_growth_array(self)

            print '====================================='
            print ' Initializing Terrestrial Properties'
            print '====================================='
            initialize.Terrestrial_Barrow(self)
            read_ice_content.read_ice_content(self)
            read_drainage_efficiency.read_drainage_efficiency(self)
            read_initial_ALD.read_initial_ALD(self)
            set_ALD_constant.set_ALD_constant(self)
            set_ALD_array.set_ALD_array(self)
            set_protective_layer.set_protective_layer(self)
            set_initial_cumulative_probability.set_initial_cumulative_probability(self)
            # Initializing Terrestrial Cohort Properties 
            initialize.Wet_NPG(self)
            initialize.Wet_LCP(self)
            initialize.Wet_CLC(self)
            initialize.Wet_FCP(self)
            initialize.Wet_HCP(self)
            # Other needed information [in the future]
            initial_cohort_age.initial_cohort_age(self)

        elif self.Simulation_area.lower() == 'tanana':
            print '======================================'
            print ' Initializing Terrestrial Properties '
            print '======================================'
            initialize.Terrestrial_Tanana(self)


        print '=================================================='
        print '            Starting the MAIN LOOP '
        print '=================================================='

        initialize.run(self)
        for time in range(0, self.stop):
            if time == 0:
                if self.Simulation_area.lower() == 'barrow':
                    cohorts.initial_barrow(self)
                elif self.Simulation_area.lower() == 'tanana':
                    cohorts.initial_tanana(self)
            print '    at time step: ', time
            
            # ++++++++++++++++++++++++++++++++++++++
            # Check for significant climatic event
            # ++++++++++++++++++++++++++++++++++++++
            check_climate_event.check_climate_event(self)            
           
            # ----------------------------------------------------------
            # Looping over elements
            # ----------------------------------------------------------
            for element in range(0, self.ATTM_nrows * self.ATTM_ncols):
                
                # ----------------------------------------------------
                # Define the total fractional area of cohorts for
                # each element
                # ----------------------------------------------------
                cohort_start = cohort_check.cohort_start(self, element, time)
                
                # ----------------------------------------------------
                # Expand/Infill lake & ponds by prescribed rates
                # ----------------------------------------------------
                lake_pond_expansion.lake_pond_expansion(self, element)
                lake_pond_expansion.pond_infill(self, element, time)
                
                # ----------------------------------------------------------
                # Set active layer depth
                # ---------------------------------------------------------
                active_layer_depth.active_layer_depth(self, time, element)
                
                # ----------------------------------
                # Cycle through terrestrial cohorts
                # ----------------------------------
                check_Wet_NPG.check_Wet_NPG(self, element, time)
                check_Wet_LCP.check_Wet_LCP(self, element, time)
                check_Wet_CLC.check_Wet_CLC(self, element, time)
                check_Wet_FCP.check_Wet_FCP(self, element, time)
                check_Wet_HCP.check_Wet_HCP(self, element, time)

                # ----------------------------------
                # Set pond/lake ice thickness depth
                # ----------------------------------
                ice_thickness.ice_thickness(self, time, element)
                # ------------------------------
                # Cycle through ponds and lakes
                # ------------------------------
                check_Ponds.check_Ponds(self, element, time)
                check_Lakes.check_Lakes(self, element, time)
                 
                # -------------------------------------------------
                # Cohort Fraction Check (mass balance of cohorts)
                # -------------------------------------------------
                cohort_check.cohort_check(self, element, time, cohort_start)

                if time == self.stop-1:
                    if self.Simulation_area.lower() == 'barrow':
                        cohorts.final_barrow(self)
                    elif self.Simulation_area.lower() == 'tanana':
                        cohorts.final_tanana(self)
                    
            # ========================================================================
            # END MAIN LOOP 
            # ========================================================================
            
            # ========================================================================
            # OUTPUT RESULTS (if requested)
            # ========================================================================
            #  - - - - - - - - -
            # Fractional Areas
            #  - - - - - - - - -
            Output_cohorts_by_year.Output_cohorts_by_year(self, time)
            #  - - - - - - - - - - - - -
            # Dominant Fractional Area
            #  - - - - - - - - - - - - - 
            Output_cohorts_by_year.dominant_cohort(self)                 # Terrestrial_Control
            Output_cohorts_by_year.dominant_fractional_plot(self, time)  # Terrestrial_Control

        # =================================
        # OUTPUT ANIMATIONS (if requested)
        # =================================
        # - - - - - - - - - - - - - - -
        # Fractional Area of Cohorts
        # - - - - - - - - - - - - - - - -
        Output_cohorts_by_year.write_Fractions_avi(self)
        Output_cohorts_by_year.write_Dominant_Cohort_avi(self) # Terrestrial_Control

        # -------------------
        # Simulation End Time
        # -------------------
        clock.finish(self)
        
        #===========================
        # Output Simulation Results
        #===========================
        if self.results_onscreen.lower() == 'yes':
            results.on_screen(self)
        if self.archive_simulation.lower() == 'yes':
            results.on_file(self)

        
        # ================
        # Archive Results
        # ================
        if self.archive_simulation.lower() == 'yes':
        #----------------------------------------------------------------------------------------------------------
        # Create the tarfile
        #----------------------------------------------------------------------------------------------------------
            self.archive_file =tarfile.open(self.control['Run_dir']+self.Output_directory+str('/Archive/')+ \
                                            self.archive_time+str('_')+self.simulation_name+".tar.gz", mode='w:gz')
        #----------------------------------------------------------------------------------------------------------
            archive.read_archive(self)
            archive.archive(self)
            
        print '----------------------------------------'
        print '        Simulation Complete             '
        print '----------------------------------------'        
示例#6
0
   f_gaus.write("                   A            \n")
   f_gaus.write("Frequencies -- {}\n ".format(omega))
   f_gaus.write("Atom  AN      X      Y      Z \n")
   for jj in range(len(vectors[:,ii1])/3):
       f_gaus.write(("{:3d} {:3d} "+"{:.2f}  "*3+'\n').format(jj+1, at_numbers[labels[jj]],*vectors[jj:jj+3,ii1]))
   kk+=1
   f_gaus.write("                   {}           \n".format(kk))
   f_gaus.write("                   A          \n")
   f_gaus.write("Frequencies -- {}\n ".format(omega))
   f_gaus.write("Atom  AN      X      Y      Z \n")
   for jj in range(len(vectors[:,ii2])/3):
       f_gaus.write(("{:3d} {:3d} "+"{:.2f}  "*3+'\n').format(jj+1, at_numbers[labels[jj]],*vectors[jj:jj+3,ii2]))
   kk+=1

atoms = labels[::3]
grads, en = read_control(control, atoms)
fs = sc.ravel(grads)
drs = sc.dot(scl.inv(hessian), fs)
print 'delta_coords'
drs_formatted = drs.view()
drs_formatted.shape= (len(drs)/3, 3)
print drs_formatted
delta_e = -sc.dot(drs, fs)
print "dE = {:.4f} a.u.".format(delta_e)
with open(delta_coord, 'w') as fout:
    fout.write('$coord_delta\n')
    for dr, at in zip(drs_formatted, atoms):
        fout.write('{} {} {} {at}\n'.format(*dr, at=at))
    fout.write('$end\n N={}\n'.format(len(drs)))
    fout.write(('{} '*len(drs)).format(*drs))
    fout.write('\n')
示例#7
0
from read_control import read_control
from read_rmc6f import read_rmc6f
from calc_neigh import calc_neigh
from read_mag_cfg import read_mag_cfg
from mag_cluster_average import mag_cluster_average

try:
    contr_file = sys.argv[1]
except:
    print "Usage: python mc_main.py CONTROL_FILE_NAME"
    sys.exit(0)

print "------------------------------------------------------------------------>"
print "First, we read in the main control file.\n"
nuc_config_name,mag_config_name,magAtmType,\
        mclusterR,outFile = read_control(contr_file)
print "<------------------------------------------------------------------------\n"

print "------------------------------------------------------------------------>"
print "Next, we proceed to read in the magnetic atoms list.\n"
metric, magAtmList = read_rmc6f(nuc_config_name)
print "<------------------------------------------------------------------------\n"

print "------------------------------------------------------------------------>"
print "Next, we move on to calculate the neighbour list.\n"
magAtmNeigh = calc_neigh(metric, magAtmList, mclusterR)
print "<------------------------------------------------------------------------\n"

print "------------------------------------------------------------------------>"
print "Next, we move on to read in the magnetic moments.\n"
mag_mom = read_mag_cfg(mag_config_name)