|
27 | 27 | from diffpy.pdfgui.control.fitstructure import FitStructure |
28 | 28 | from diffpy.pdfgui.control.controlerrors import ControlError |
29 | 29 | from diffpy.pdfgui.control.controlerrors import ControlFileError |
30 | | -from diffpy.pdfgui.control.controlerrors import ControlRuntimeError |
31 | 30 | from diffpy.pdfgui.control.controlerrors import ControlTypeError |
32 | 31 |
|
33 | 32 |
|
@@ -333,74 +332,6 @@ def paste(self, dup, target=None, new_name=None, position=None): |
333 | 332 | target.add(o, position) |
334 | 333 | return o |
335 | 334 |
|
336 | | - def importPdffit2Script(self, scriptfile, args=[]): |
337 | | - """add fits and calculations from pdffit2 script |
338 | | -
|
339 | | - scriptfile -- path to old pdffit2 script |
340 | | - args -- optional arguments passed to scriptfile |
341 | | -
|
342 | | - returns list of imported fits |
343 | | - """ |
344 | | - pyexe = sys.executable |
345 | | - # Build python command to be executed in the child process. |
346 | | - pycommand = '\n'.join([ |
347 | | - 'from diffpy.pdfgui.control.dumppdffit2script import main', |
348 | | - 'main()', |
349 | | - ]) |
350 | | - # Build argument list. Include the '-u' option so that child |
351 | | - # Python opens it input and output streams in binary mode. |
352 | | - cmdargs = [pyexe, '-u', '-c', pycommand, scriptfile] + args |
353 | | - scriptdir = os.path.dirname(scriptfile) |
354 | | - import platform |
355 | | - from subprocess import Popen, PIPE |
356 | | - cfds = (platform.system() != 'Windows') |
357 | | - pcmd = Popen(cmdargs, cwd=scriptdir, |
358 | | - stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=cfds) |
359 | | - # close child standard input |
360 | | - out, err = pcmd.communicate() |
361 | | - status = pcmd.wait() |
362 | | - if status != 0: |
363 | | - raise ControlRuntimeError, \ |
364 | | - "Import of pdffit2 script failed:\n" + err |
365 | | - # seems that everything worked fine here |
366 | | - import cPickle |
367 | | - impfits = cPickle.loads(out) |
368 | | - orgnames = [ f.name for f in impfits ] |
369 | | - usednames = dict.fromkeys([ f.name for f in self.fits ]) |
370 | | - basename, ext = os.path.splitext(os.path.basename(scriptfile)) |
371 | | - start = 0 |
372 | | - while True: |
373 | | - start = start + 1 |
374 | | - newnames = [ basename + str(i) \ |
375 | | - for i in range(start, start+len(impfits)) ] |
376 | | - anyused = [ n for n in newnames if n in usednames ] |
377 | | - if not anyused: |
378 | | - break |
379 | | - # here we have correct new names |
380 | | - # build a dictionary with name translations |
381 | | - old2new = dict(zip(orgnames, newnames)) |
382 | | - for fit in impfits: |
383 | | - # items in impfits were stripped, we need to insert normal copy |
384 | | - clothed = fit.copy() |
385 | | - clothed.name = old2new[fit.name] |
386 | | - # take care of linked parameters: |
387 | | - if isinstance(clothed, Fitting): |
388 | | - for idx, par in clothed.parameters.iteritems(): |
389 | | - inistr = par.initialStr() |
390 | | - if inistr[:1] == "=": |
391 | | - iniwords = inistr[1:].split(':') |
392 | | - if len(iniwords) == 1: |
393 | | - ininame = iniwords[0] |
394 | | - srcparidx = str(idx) |
395 | | - else: |
396 | | - ininame = ':'.join(iniwords[:-1]) |
397 | | - srcparidx = iniwords[-1] |
398 | | - newlinkedname = old2new[ininame] |
399 | | - par.setInitial("=%s:%s" % (newlinkedname, srcparidx)) |
400 | | - # finally we can put it in |
401 | | - self.add(clothed) |
402 | | - newfits = self.fits[len(self.fits)-len(impfits):] |
403 | | - return [obj.organization() for obj in newfits] |
404 | 335 |
|
405 | 336 | def load(self, projfile): |
406 | 337 | """load project from projfile. |
|
0 commit comments