Changeset 415
- Timestamp:
- Nov 15, 2011 9:07:55 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r411 r415 1509 1509 screenSize = wx.ClientDisplayRect() 1510 1510 Size = dlg.GetSize() 1511 Size = (int(Size[0]*1.2),Size[1]) # increase size a bit along x 1511 1512 dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5)) 1513 dlg.SetSize(Size) 1512 1514 try: 1513 1515 G2str.Refine(self.GSASprojectfile,dlg) … … 1544 1546 screenSize = wx.ClientDisplayRect() 1545 1547 Size = dlg.GetSize() 1548 Size = (int(Size[0]*1.2),Size[1]) # increase size a bit along x 1546 1549 dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5)) 1550 dlg.SetSize(Size) 1547 1551 try: 1548 1552 G2str.SeqRefine(self.GSASprojectfile,dlg) … … 1617 1621 def main(): 1618 1622 application = GSASIImain(0) 1623 #application.main.OnRefine(None) 1619 1624 application.MainLoop() 1620 1625 1621 1626 if __name__ == '__main__': 1622 1627 main() -
trunk/GSASIIgrid.py
r413 r415 18 18 import GSASIIphsGUI as G2phG 19 19 import GSASIIstruct as G2str 20 import GSASIImapvars as G2mv20 #import GSASIImapvars as G2mv 21 21 22 22 [ wxID_ATOMSEDITADD, wxID_ATOMSEDITINSERT, wxID_ATOMSEDITDELETE, wxID_ATOMSREFINE, -
trunk/GSASIImapvars.py
r411 r415 90 90 each group. This contains both parameters used in parameter 91 91 redefinitions as well as names of generated new parameters. 92 92 93 fixedVarList: a list of variables that have been 'fixed' 94 by defining them as equal to a constant (::var: = 0). Note that 95 the constant value is ignored at present. These variables are 96 later removed from varyList which prevents them from being refined. 97 Unlikely to be used externally. 93 98 arrayList: a list by group of relationship matrices to relate 94 99 parameters in dependentParmList to those in indParmList. Unlikely … … 115 120 fixedDict = {} # a dictionary containing the fixed values corresponding to defined parameter equations 116 121 # key is original ascii string, value is float 122 fixedVarList = [] # List of variables that should not be refined 117 123 118 124 # compile regular expressions used for parsing input 119 125 rex_mult = re.compile('[+-]?[0-9.]+[eE]?[+-]?[0-9]*') 120 126 rex_star = re.compile('\s*\*\s*') 121 rex_var = re.compile(' \w+')127 rex_var = re.compile('[a-zA-Z0-9_:]+') 122 128 rex_plusminus = re.compile('\s*[+-=]\s*') 123 129 rex_vary = re.compile('\s*Vary\s*', re.IGNORECASE) … … 137 143 fixedDict = {} # a dictionary containing the fixed values corresponding to defined parameter equations 138 144 consNum = 0 # number of the next constraint to be created 145 fixedVarList = [] 139 146 140 147 def InputParse(mapList): … … 185 192 if debug: print 50*'-','\n(Input)' 186 193 for line in mapList: 194 inputline = line[:] 187 195 line = line.strip() 188 196 if len(line) == 0: continue # empty lines are ignored … … 243 251 else: 244 252 # something else is on the line, but not a keyword 245 raise Exception 253 raise Exception,'Error in line '+str(inputline)+'\nat '+str(line) 246 254 except SyntaxError: 247 255 if debug: print 'Error in line',i,'token',j,'@','"'+line+'"' … … 307 315 for row in group: 308 316 if 'VaryFree' in constrFlag[row]: VaryFree = True 317 if len(varlist) == 1: 318 #print "Debug: Fixing parameter (%s)" % (varlist[0]) 319 fixedVarList.append(varlist[0]) 320 continue 309 321 arr = MakeArray(constrDict, group, varlist) 310 322 constrArr = FillInMissingRelations(arr,len(group)) … … 382 394 return 383 395 396 def SetVaryFlags(varyList): 397 '''Adds independent variables to the varyList provided that all 398 dependent variables are being varied. 399 Ignores independent variables where no dependent variables are 400 being varied. 401 Returns a non-empty text message where some but not all dependent 402 variables are being varied. 403 ''' 404 global dependentParmList,arrayList,invarrayList,indParmList,fixedDict 405 for varlist,mapvars,multarr in zip(dependentParmList,indParmList,arrayList): 406 msg = "" 407 for mv in mapvars: 408 varied = [] 409 notvaried = [] 410 if mv in fixedDict: continue 411 if multarr is None: 412 if mv in varyList: 413 varied.append(mv) 414 else: 415 notvaried.append(mv) 416 for v in varlist: 417 if v in varyList: 418 varied.append(v) 419 else: 420 notvaried.append(v) 421 if len(varied) > 0 and len(notvaried) > 0: 422 if msg != "": msg += "\n" 423 msg += "Error: inconsistent use of parameter " + mv 424 msg += "\n varied: " 425 for v in varied: msg += v 426 msg += "\n not varied: " 427 for v in notvaried: msg += v 428 elif len(varied) > 0 and multarr is not None: 429 varyList.append(mv) 430 return msg 431 432 384 433 def VarRemapShow(varyList): 385 434 '''List out the saved relationships. 386 435 Returns a string containing the details. 387 436 ''' 388 s = 'Mapping relations:\n' 437 s = '' 438 if len(fixedVarList) > 0: 439 s += 'Fixed Variables:\n' 440 for v in fixedVarList: 441 s += ' ' + v + '\n' 442 s += 'Variable mapping relations:\n' 389 443 global dependentParmList,arrayList,invarrayList,indParmList,fixedDict 390 444 for varlist,mapvars,multarr in zip(dependentParmList,indParmList,arrayList): … … 410 464 s += '\n' 411 465 i += 1 412 s += 'Inverse mapping relations:\n'466 s += 'Inverse variable mapping relations:\n' 413 467 for varlist,mapvars,invmultarr in zip(dependentParmList,indParmList,invarrayList): 414 468 i = 0 … … 429 483 set of Parameters 430 484 485 Removes dependent variables from the varyList 486 431 487 This should be done once, before any variable refinement is done 432 488 to complete the parameter dictionary with the Independent Parameters 433 489 ''' 490 # process the Independent vars: remove dependent ones from varylist 491 # and then compute values for the Independent ones from their dependents 434 492 global dependentParmList,arrayList,invarrayList,indParmList,fixedDict 435 493 for varlist,mapvars,multarr in zip(dependentParmList,indParmList,arrayList): … … 444 502 np.dot(multarr,np.array(valuelist))) 445 503 ) 446 # overwrite dict with constraints - why not parmDict.update(fixDict)? 504 # now remove fixed variables from the varyList 505 global fixedVarList 506 for item in fixedVarList: 507 try: 508 varyList.remove(item) 509 except ValueError: 510 pass 511 # Set constrained parameters to their fixed values 447 512 parmDict.update(fixedDict) 448 513 … … 537 602 raise Exception,'The number of relationships (%d) exceeds the number of parameters (%d):\n\t%s\n\t%s'% ( 538 603 len(group),len(varlist),group,varlist) 539 if len(varlist) == 1: # one to one mapping -- something is probably wrong540 raise Exception,'Why remap a single parameter? (%s)'% (varlist[0])541 604 # put the coefficients into an array 542 605 multarr = np.zeros(2*[len(varlist),]) … … 637 700 parmdict = {} 638 701 StoreEquivalence('2::atomx:3',('2::atomy:3', ('2::atomz:3',2,), )) 639 print VarRemapShow() 640 641 parmdict = { 642 '2::atomx:3':.1 , 643 '2::atomy:3':.2 , # conflicts with constraint 644 '2::atomz:3':.3 , 645 } 646 702 varylist = ['2::atomx:3',] 703 print VarRemapShow(varylist) 704 msg = SetVaryFlags(varylist) 705 if msg != "": print msg 706 varylist = ['2::atomx:3', '2::atomy:3', '2::atomz:3',] 707 print VarRemapShow(varylist) 708 msg = SetVaryFlags(varylist) 709 if msg != "": print msg 710 #parmdict = { 711 # '2::atomx:3':.1 , 712 # '2::atomy:3':.2 , # conflicts with constraint 713 # '2::atomz:3':.3 , 714 #} 715 716 varylist = [] 717 mapList1 = [ 718 "1 * 2::atomz:3 = 0", 719 "1*p1 + 2e0*p2 - 1.0*p3", 720 "1*p4 + 1*p7", 721 "1*p1+2*p2-3.0*p2 VARY", 722 ] 647 723 mapList = [ 724 "1 * 2::atomz:3 = 0", 648 725 "1*p1 + 2e0*p2 - 1.0*p3", 649 726 "1*p4 + 1*p7", … … 654 731 "-10e-1 * p1 - -2*p2 + 3.0*p4", 655 732 ] 656 constrDict,constrFlag,fixedList = InputParse(mapList )657 print constrDict658 print constrFlag659 print fixedList733 constrDict,constrFlag,fixedList = InputParse(mapList1) 734 #print constrDict 735 #print constrFlag 736 #print fixedList 660 737 groups,parmlist = GroupConstraints(constrDict) 661 GenerateConstraints(groups,parmlist,constrDict,constrFlag,fixedList) 662 print VarRemapShow() 738 GenerateConstraints(groups,parmlist,varylist,constrDict,constrFlag,fixedList) 739 print VarRemapShow(varylist) 740 sys.exit() 663 741 parmdict.update( {'p1':1,'p2':2,'p3':3,'p4':4, 664 742 'p6':6,'p5':5, # conflicts with constraint -
trunk/GSASIIstruct.py
r411 r415 236 236 import distutils.file_util as dfu 237 237 GPXpath,GPXname = ospath.split(GPXfile) 238 if GPXpath == '': GPXpath = '.' 238 239 Name = ospath.splitext(GPXname)[0] 239 240 files = os.listdir(GPXpath) … … 2453 2454 print ' *** ERROR - you have no data to refine with! ***' 2454 2455 print ' *** Refine aborted ***' 2455 raise Exception 2456 raise Exception 2456 2457 Natoms,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables = GetPhaseData(Phases) 2457 2458 calcControls['Natoms'] = Natoms … … 2467 2468 parmDict.update(histDict) 2468 2469 GetFprime(calcControls,Histograms) 2469 groups,parmlist = G2mv.GroupConstraints(constrDict) 2470 G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,constrFlag,fixedList) 2470 # do constraint processing 2471 try: 2472 groups,parmlist = G2mv.GroupConstraints(constrDict) 2473 G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,constrFlag,fixedList) 2474 except: 2475 print ' *** ERROR - your constraints are internally inconsistent ***' 2476 print ' *** Refine aborted ***' 2477 raise Exception 2478 # check to see which generated parameters are fully varied 2479 msg = G2mv.SetVaryFlags(varyList) 2480 if msg: 2481 print ' *** ERROR - you have not set the refine flags for constraints consistently! ***' 2482 print msg 2483 print ' *** Refine aborted ***' 2484 raise Exception 2485 G2mv.Map2Dict(parmDict,varyList) 2471 2486 print G2mv.VarRemapShow(varyList) 2472 G2mv.Map2Dict(parmDict,varyList)2473 2487 2474 2488 while True: -
trunk/fsource/pypowder.for
r355 r415 126 126 END 127 127 128 C Fortran (fast) linear interpolation -- B.H. Toby 9/2011 129 SUBROUTINE PYFINTERP(NIN,XIN,YIN,NOUT,XOUT,YOUT) 130 C XIN(1:NIN) and YIN(1:NIN) are arrays of (x,y) points to be interpolated 131 C Values must be sorted increasing in XIN 132 C XOUT(1:NOUT) is an array of x values, must also be sorted increasing in x 133 C XOUT may contain values smaller than XIN(1) or larger than XIN(NIN) 134 C RETURNS interpolated y values corresponding to XOUT. Values outside the 135 C range of XIN are set to zero. 136 C Needs a way to signal an error if XIN or XOUT is not sorted -- for now stops 137 Cf2py intent(in) NIN 138 Cf2py intent(in) XIN 139 cf2py depend(NIN) XIN 140 Cf2py intent(in) YIN 141 cf2py depend(NIN) YIN 142 Cf2py intent(in) NOUT 143 Cf2py intent(in) XOUT 144 cf2py depend(NOUT) XOUT 145 Cf2py intent(out) YOUT 146 cf2py depend(NOUT) YOUT 147 148 REAL XIN(NIN),YIN(NIN) 149 REAL XOUT(NOUT),YOUT(NOUT) 150 INTEGER IERROR 151 REAL X,F 152 INTEGER IIN,I 153 154 IERROR = 1 155 IIN = 1 156 X = XOUT(1) 157 DO I=1,NOUT 158 IF (X .GT. XOUT(I)) STOP ! test if Xout not sorted 159 X = XOUT(I) 160 IF (X .LT. XIN(1) .OR. X .GT. XIN(NIN) ) THEN 161 YOUT(I) = 0.0 162 ELSE 163 DO WHILE (X .GT. XIN(IIN+1)) 164 IF (XIN(IIN) .GT. XIN(IIN+1)) STOP ! test if Xin not sorted 165 IIN = IIN + 1 166 ENDDO 167 F = (X - XIN(IIN)) / (XIN(IIN+1) - XIN(IIN)) 168 YOUT(I) = (1.-F)*YIN(IIN) + F*YIN(IIN+1) 169 ENDIF 170 !write (*,*) xout(i),iin,f,yout(i) 171 END DO 172 IERROR = 0 173 RETURN 174 END
Note: See TracChangeset
for help on using the changeset viewer.