Ignore:
Timestamp:
Nov 7, 2011, 4:13:18 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:
5ab796
Parents:
f89b45
git-author:
Frederik Heber <heber@…> (11/02/11 01:17:53)
git-committer:
Frederik Heber <heber@…> (11/07/11 16:13:18)
Message:

Changed GetSourceMolareMass() and GetSourceBBabs() of boxmaker.py.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • utils/boxmaker.py.in

    rf89b45 rf894fe  
    135135   
    136136    # Redo with pipes?
     137    #sys.stdout.write("units '%s' '%s'\n" % (have, want))
    137138    ret = os.system("units '%s' '%s' > temp_units_output" % (have, want))
    138139
     
    148149       
    149150       
    150 def GetSourceMolareMass(opt):
    151     with open(opt.potentialsfiledir+opt.basename+'.potentials') as f:
    152         potfile = f.read()
    153        
    154     elementmasses = dict(re.findall(r'element_name=(\w{1,2}).*?mass=([0-9.]*)', potfile))
    155    
    156     for key in elementmasses:
    157         elementmasses[key] = float(elementmasses[key])
    158    
    159     mass_sum = 0.0
    160    
    161     with open('temp_source.xyz') as f:
    162         N = int(f.readline())
    163         comment = f.readline()
    164        
    165         for i in range(N):
    166             elem = f.readline().split(None, 1)[0].strip()
    167             mass_sum += elementmasses[elem]
    168 
    169     return mass_sum*avogadro
     151def GetSourceMolareMass(opt, units):
     152    mol.SelectionAllAtoms()
     153    mass_sum = mol.AnalysisCalculateMolarMass()
     154    have = ("%f atomicmassunit" % mass_sum)
     155    want = ("%f*%s" % tuple(units['mass']))
     156    return ConvertUnits(have, want)*avogadro
    170157
    171158
     
    221208        opt.number = int(opt.number)
    222209       
    223     UpdateSource(opt)
     210    InitialiseSource(opt)
    224211       
    225212    # Automatic source mass
    226213    if opt.automass:
    227         opt.molarmass = GetSourceMolareMass(opt)
     214        opt.molarmass = GetSourceMolareMass(opt, units)
    228215        print '======== MOLAR MASS:', opt.molarmass
    229216
     
    291278
    292279def GetSourceBBabs(opt):
    293     bbmax = [0.0]*3
    294     bbmin = [float('inf')]*3
    295 
    296     s_name_ext = os.path.basename(opt.source).rsplit('.', 1)
    297     s_namepart = s_name_ext[0]
    298 
    299     if len(s_name_ext) > 1:
    300         s_ext = s_name_ext[1]
    301     else:
    302         s_ext = ''
    303 
    304     # Calculate bounding box from xyz-file
    305     with open('temp_source.xyz') as f:
    306         N = int(f.readline())
    307         comment = f.readline()
    308 
    309         for i in xrange(N):
    310             buf = f.readline()
    311             xyz = buf.split()[1:]
    312 
    313             for i in range(3):
    314                 bbmax[i] = max(bbmax[i], float(xyz[i]))
    315                 bbmin[i] = min(bbmin[i], float(xyz[i]))
     280    mol.WorldCenterOnEdge()
     281    bb = mol.AnalysisCalculateBoundingBox()
     282    bbmin = [bb[0], bb[2], bb[4]]
     283    bbmax = [bb[1], bb[3], bb[5]]
    316284
    317285    bb = [0.0]*3
     
    323291   
    324292   
    325 def UpdateSource(opt):
     293def InitialiseSource(opt):
    326294    potfilepath = opt.potentialsfiledir + opt.basename + '.potentials'
    327     mol.ParserSetOutputFormats("xyz tremolo")
    328295    mol.ParserParseTremoloPotentials(potfilepath)
    329296    mol.MoleculeLoad(opt.source)
    330    
    331     #cmd = 'molecuilder -o xyz tremolo --parse-tremolo-potentials %s -i temp_source.xyz -l %s' % (potfilepath, opt.source)
    332297   
    333298    if opt.autorotate:
    334299        mol.SelectAllAtoms()
    335300        mol.RotateToPrincipalAxisSystem("0 1 0")
    336         #cmd += ' --select-all-atoms --rotate-to-principal-axis-system "0, 1, 0"'
    337     mol.WorldOutput('temp_source' + '.data')
    338     mol.WorldOutput('temp_source' + '.xyz')
    339        
    340     #os.system(cmd)
    341     mol.reinit()
    342        
    343     opt.source = 'temp_source.data'
    344 
    345301
    346302# Global options with sensible default parameters
     
    381337
    382338mol.CommandVerbose('0')
    383 mol.ParserParseTremoloPotentials(opt.potentialsfiledir + opt.basename + '.potentials')
    384 mol.WorldInput(opt.source)
    385339mol.WorldCenterInBox('%f 0 0 %f 0 %f' % tuple(cell))
    386340mol.WorldRepeatBox('%d %d %d' % tuple(nbox))
Note: See TracChangeset for help on using the changeset viewer.