Changeset c0c85f for utils


Ignore:
Timestamp:
Nov 7, 2011, 4:12:25 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
bfbb62
Parents:
b82ede
git-author:
Gregor Bollerhey <bollerhe@…> (10/20/11 13:16:38)
git-committer:
Frederik Heber <heber@…> (11/07/11 16:12:25)
Message:

Restructured Code

  • temp_source.xyz is created only once
  • boolean mapping with dict rather than if-tree
File:
1 edited

Legend:

Unmodified
Added
Removed
  • utils/boxmaker.py

    rb82ede rc0c85f  
    139139       
    140140       
    141 def GetSourcMolareMass(opt):
     141def GetSourceMolareMass(opt):
    142142    with open(opt.potentialsfiledir+opt.basename+'.potentials') as f:
    143143        potfile = f.read()
     
    147147    for key in elementmasses:
    148148        elementmasses[key] = float(elementmasses[key])
    149    
    150     # Convert from any format to xyz
    151     os.system('molecuilder -o xyz --parse-tremolo-potentials %s -i temp_source.xyz -l %s' % (opt.potentialsfiledir+opt.basename+'.potentials', opt.source))
    152149   
    153150    mass_sum = 0.0
     
    160157            elem = f.readline().split(None, 1)[0].strip()
    161158            mass_sum += elementmasses[elem]
    162            
    163     os.system('rm temp_source*')     
     159
    164160    return mass_sum*avogadro
    165161
    166162
    167 def UpdateSettings(opt):
     163def UpdateSettingsAndSource(opt):
    168164    # Map boolean values
     165    boolmap = {'on': True, 'off': False}
     166   
    169167    for name in ['cubicdomain', 'cubiccell', 'autorotate', 'autodim', 'postprocess', 'automass']:
    170168        value = eval('opt.' + name)
    171169       
    172         if value == 'on':
    173             value = True
    174         elif value == 'off':
    175             value = False
     170        if value in boolmap:
     171            value = boolmap[value]
    176172        else:
    177173            print 'Not a boolean value:', value
     
    216212        opt.number = int(opt.number)
    217213       
     214    UpdateSource(opt)
     215       
    218216    # Automatic source mass
    219217    if opt.automass:
    220         opt.molarmass = GetSourcMolareMass(opt)
     218        opt.molarmass = GetSourceMolareMass(opt)
    221219        print '======== MOLAR MASS:', opt.molarmass
    222220
     
    295293        s_ext = ''
    296294
    297     # Convert from any format to xyz
    298     os.system('molecuilder -o xyz --parse-tremolo-potentials %s -i temp_source.xyz -l %s' % (opt.potentialsfiledir+opt.basename+'.potentials', opt.source))
    299 
    300295    # Calculate bounding box from xyz-file
    301296    with open('temp_source.xyz') as f:
     
    316311        bb[i] = abs(bbmax[i] - bbmin[i])
    317312
    318     os.system('rm temp_source.*')
    319313    return bb
     314   
     315   
     316def UpdateSource(opt):
     317    potfilepath = opt.potentialsfiledir + opt.basename + '.potentials'
     318   
     319    cmd = 'molecuilder -o xyz tremolo --parse-tremolo-potentials %s -i temp_source.xyz -l %s' % (potfilepath, opt.source)
     320   
     321    if opt.autorotate:
     322        cmd += ' --select-all-atoms --rotate-to-principal-axis-system "0, 1, 0"'
     323       
     324    os.system(cmd)
     325       
     326    opt.source = 'temp_source.data'
     327
    320328
    321329# Global options with sensible default parameters
     
    323331
    324332ReadSettings(opt)
    325 UpdateSettings(opt)
     333UpdateSettingsAndSource(opt)
    326334
    327335if type(opt.number) == type([]):
     
    333341    else:
    334342        nbox = FindBestCuboid(opt)
    335        
    336 # Autorotate
    337 if opt.autorotate:
    338     os.system('molecuilder --parse-tremolo-potentials %s -i rotated_temp_source.data -l %s --rotate-to-principal-axis-system "1, 0, 0"' % (opt.potentialsfiledir+opt.basename+'.potentials', opt.source))
    339     opt.source = 'rotated_temp_source.data'
    340343
    341344VolumePerMolecule = opt.molarmass / (avogadro * opt.density)
     
    390393        f.write(ofile)
    391394       
    392 if opt.autorotate:
    393     os.system('rm ' + opt.source)
     395os.system('rm temp_source.data temp_source.xyz')
Note: See TracChangeset for help on using the changeset viewer.