Example #1
0
def gpvdm_clone(path,src_archive="",copy_dirs=False,dest="archive"):
	if src_archive=="":
		src_dir=get_inp_file_path()
		src_archive=os.path.join(src_dir,"base.gpvdm")
		
	dest_archive=os.path.join(path,"sim.gpvdm")
	files=zip_lsdir(src_archive)
	lines=[]

	archive_make_empty(dest_archive)

	for i in range(0,len(files)):
		if files[i].endswith(".inp"):
			lines=read_lines_from_archive(src_archive,files[i])
			write_lines_to_archive(dest_archive,files[i],lines,dest=dest)


	if copy_dirs==True:
		if os.path.isdir(os.path.join(src_dir,"plot")):
			shutil.copytree(os.path.join(src_dir,"plot"), os.path.join(path,"plot"))

		if os.path.isdir(os.path.join(src_dir,"exp")):
			shutil.copytree(os.path.join(src_dir,"exp"), os.path.join(path,"exp"))

		#if os.path.isdir(os.path.join(src_dir,"materials")):
		#	shutil.copytree(os.path.join(src_dir,"materials"), os.path.join(path,"materials"))

		#clone_materials(path)
		clone_spectras(path)
    def callback_home_backup(self):
        backup_path = get_backup_path()
        if os.path.isdir(backup_path) == False:
            os.makedirs(backup_path)

        lines = []
        lines.append("#gpvdm_file_type")
        lines.append("backup_main")
        lines.append("#end")

        write_lines_to_archive(os.path.join(backup_path, "sim.gpvdm"),
                               "mat.inp",
                               lines,
                               mode="l",
                               dest="file")

        self.dialog = gpvdm_open(backup_path, big_toolbar=True)
        self.new_backup = QAction_lock("add_backup",
                                       wrap_text(_("New backup"), 2), self,
                                       "add_backup")
        self.new_backup.clicked.connect(self.on_new_backup)
        self.dialog.toolbar.addAction(self.new_backup)

        self.dialog.viewer.show_inp_files = False
        ret = self.dialog.exec_()
Example #3
0
def gpvdm_clone(path, src_archive="", copy_dirs=False, dest="archive"):
    #print("Cloning from",get_inp_file_path())

    if src_archive == "":
        src_dir = get_inp_file_path()
        src_archive = os.path.join(src_dir, "base.gpvdm")

    dest_archive = os.path.join(path, "sim.gpvdm")
    files = zip_lsdir(src_archive)
    lines = []

    archive_make_empty(dest_archive)

    for i in range(0, len(files)):
        if files[i].endswith(".inp"):
            lines = read_lines_from_archive(src_archive, files[i], mode="b")
            write_lines_to_archive(dest_archive,
                                   files[i],
                                   lines,
                                   dest=dest,
                                   mode="b")
            #if (files[i]=="dos0.inp"):
            #	asdsa

    if copy_dirs == True:
        if os.path.isdir(os.path.join(src_dir, "plot")):
            shutil.copytree(os.path.join(src_dir, "plot"),
                            os.path.join(path, "plot"))

        if os.path.isdir(os.path.join(src_dir, "exp")):
            shutil.copytree(os.path.join(src_dir, "exp"),
                            os.path.join(path, "exp"))
Example #4
0
def backup(dest, src, notes=""):

    if os.path.isdir(dest) == False:
        os.makedirs(dest)

    lines = []
    lines.append("#gpvdm_file_type")
    lines.append("backup")
    lines.append("#date")
    lines.append(str(datetime.datetime.now()))
    lines.append("#notes")
    lines.append(notes)
    lines.append("#end")

    write_lines_to_archive(os.path.join(dest, "sim.gpvdm"),
                           "mat.inp",
                           lines,
                           mode="l",
                           dest="file")

    for f in os.listdir(src):
        if f.endswith(".inp") or f == "sim.gpvdm":
            src_file = os.path.join(src, f)
            dst_file = os.path.join(dest, f)
            copyfile(src_file, dst_file)
Example #5
0
def gpvdm_clone(dest,copy_dirs,materials=["all"]):
	src_dir=get_inp_file_path()
	src_archive=os.path.join(src_dir,"sim.gpvdm")
	dest_archive=os.path.join(dest,"sim.gpvdm")
	print(src_archive)
	files=zip_lsdir(src_archive)
	lines=[]

	archive_make_empty(dest_archive)

	for i in range(0,len(files)):
		if files[i].endswith(".inp"):
			read_lines_from_archive(lines,src_archive,files[i])
			write_lines_to_archive(dest_archive,files[i],lines)


	if copy_dirs==True:
		if os.path.isdir(os.path.join(src_dir,"plot")):
			shutil.copytree(os.path.join(src_dir,"plot"), os.path.join(dest,"plot"))

		if os.path.isdir(os.path.join(src_dir,"exp")):
			shutil.copytree(os.path.join(src_dir,"exp"), os.path.join(dest,"exp"))

		if os.path.isdir(os.path.join(src_dir,"materials")):
			shutil.copytree(os.path.join(src_dir,"materials"), os.path.join(dest,"materials"))

		clone_materials(dest,materials)
def copy_check_ver(dest_archive,src_archive,file_name,only_over_write,clever):
	if dest_archive==src_archive:
		print "I can't opperate on the same .opvdm file"
		return
	#remove the dest file if both exist ready to copy
	do_copy=True
	src_ver=""
	dest_ver=""
	orig_exists=False
	dest_exists=False
	src_lines=[]
	dest_lines=[]

	orig_exists=read_lines_from_archive(src_lines,src_archive,file_name)

	if orig_exists==True:
		src_ver=inp_search_token_value(src_lines, "#ver")
	else:
		print "Warning: ",src_archive,file_name," no origonal file to copy"
		return

	#read in the dest file where ever it may be
	dest_exists=read_lines_from_archive(dest_lines,dest_archive,file_name)

	if dest_exists==True:
		dest_ver=inp_search_token_value(dest_lines, "#ver")

		
	#if we are only over writing only copy if dest file exists
	if (only_over_write==True):
		if dest_exists==True:
			do_copy=True
		else:
			print "Warning: ", file_name," - only exists in the source"
			do_copy=False
			return

	if dest_exists==True:
		if src_ver!=dest_ver:
			print "Warning: Verstion numbers do not match for files",dest_archive,src_archive,file_name
			print "src_ver=",src_ver,"dest ver=",dest_ver

			if clever==False:
				print "Not copying that file you will have to deal that with by hand"
				return

	if clever==True and dest_exists==True:
		errors=inp_merge(dest_lines,src_lines) 
		if len(errors)!=0:
			print "File ",file_name,errors
	else:
		dest_lines=src_lines

	if (do_copy==True):
		write_lines_to_archive(dest_archive,file_name,dest_lines)
Example #7
0
def inp_update_token_array(file_path, token, replace):
    lines = []
    base_name = os.path.basename(file_path)
    path = os.path.dirname(file_path)

    zip_file_name = os.path.join(path, "sim.gpvdm")

    lines = read_lines_from_archive(zip_file_name, os.path.basename(file_path))

    lines = inp_replace_token_array(lines, token, replace)

    write_lines_to_archive(zip_file_name, base_name, lines)
Example #8
0
 def save(self, mode="l", dest="archive"):
     """Write save lines to a file"""
     ret = write_lines_to_archive(self.zip_file_path,
                                  self.file_name,
                                  self.lines,
                                  mode=mode,
                                  dest=dest)
     return ret
Example #9
0
def inp_save(file_path, lines, archive="sim.gpvdm"):
    """Write save lines to a file"""

    full_path = default_to_sim_path(file_path)
    archive_path = os.path.join(os.path.dirname(full_path), archive)
    file_name = os.path.basename(full_path)
    #print("archive",archive_path)
    #print("file",file_name)
    #print(lines)
    return write_lines_to_archive(archive_path, file_name, lines)
Example #10
0
def inp_save(file_path, lines, archive="sim.gpvdm", id=""):
    """Write save lines to a file"""

    full_path = default_to_sim_path(file_path)
    archive_path = os.path.join(os.path.dirname(full_path), archive)
    file_name = os.path.basename(full_path)
    #print("archive",archive_path)
    #print("file",file_name)
    #print(lines)

    ret = write_lines_to_archive(archive_path, file_name, lines)

    if id != "":
        inp_callback_check_hook(file_path, id)

    return ret
Example #11
0
def inp_write_lines_to_file(file_path,lines):
	archive_path=os.path.join(os.path.dirname(file_path),"sim.gpvdm")
	file_name=os.path.basename(file_path)
	return write_lines_to_archive(archive_path,file_name,lines)
Example #12
0
def extract_data(path, driver):
    html = driver.page_source.split("\n")
    for i in range(0, len(html)):
        if html[i].count(
                "OutputDataTable") > 3:  #<tr><td class=\'OutputDataTable\'>
            lines_n = []
            lines_n.append("#gpvdm")
            lines_n.append("#title Refractive index")
            lines_n.append("#type xy")
            lines_n.append("#x_mul 1e9")
            lines_n.append("#y_mul 1.000000")
            lines_n.append("#x_label Wavelength")
            lines_n.append("#data_label Refractive index")
            lines_n.append("#x_units nm")
            lines_n.append("#data_units m^{-1}")
            lines_n.append("#logscale_x 0")
            lines_n.append("#logscale_y 0")
            lines_n.append("#section_one Materials")
            lines_n.append("#section_two Refractive index")
            lines_n.append("#data")

            lines_alpha = []
            lines_alpha.append("#gpvdm")
            lines_alpha.append("#title Absorption")
            lines_alpha.append("#type xy")
            lines_alpha.append("#x_mul 1e9")
            lines_alpha.append("#y_mul 1.000000")
            lines_alpha.append("#x_label Wavelength")
            lines_alpha.append("#data_label Absorption")
            lines_alpha.append("#x_units nm")
            lines_alpha.append("#data_units m^{-1}")
            lines_alpha.append("#logscale_x 0")
            lines_alpha.append("#logscale_y 0")
            lines_alpha.append("#section_one Materials")
            lines_alpha.append("#section_two Absorption")
            lines_alpha.append("#data")

            data = html[i]
            data = data.replace("<td class=\"OutputDataTable\">", " ")
            data = BeautifulSoup(data, "lxml").text
            data = data.replace(u"\xa0", "")
            numbers = data.split()
            lines = int(len(numbers) / 5)
            for i in range(0, lines):
                pos = i * 5
                lam = float(numbers[pos]) * 1e-9
                n = float(numbers[pos + 1])
                alpha = float(numbers[pos + 4]) * 100.0
                #print(lam,n,alpha)
                lines_n.append(str(lam) + " " + str(n))
                lines_alpha.append(str(lam) + " " + str(alpha))

            #return "hello"#cleantext
            write_lines_to_archive(path,
                                   "alpha.omat",
                                   lines_alpha,
                                   mode="l",
                                   dest="file")
            write_lines_to_archive(path,
                                   "n.omat",
                                   lines_n,
                                   mode="l",
                                   dest="file")
            zip_remove_file(path, "cost.xlsx")

            zip_remove_file(path, "n_eq.inp")
            zip_remove_file(path, "alpha_eq.inp")

            zip_remove_file(path, "n_gen.omat")
            zip_remove_file(path, "alpha_gen.omat")

    return None