コード例 #1
0
ファイル: graph.py プロジェクト: nikmedoed/pybinar
def plot(c, d, name="", fold='', show=False):
    plt.clf()
    loc = localisation.loc(__file__)
    index = np.arange(13)
    bar_width = 0.35
    opacity = 0.8

    plt.grid(True, linestyle=':', fillstyle='bottom', axis='y')
    rects1 = plt.bar(index - bar_width / 2,
                     d,
                     bar_width,
                     alpha=opacity,
                     color='tab:purple',
                     label=loc['Bar1'])

    rects2 = plt.bar(index + bar_width / 2,
                     c,
                     bar_width,
                     alpha=opacity,
                     color='orange',
                     label=loc['Bar2'])

    plt.xlabel(loc['XLabel'])
    plt.ylabel(loc['YLabel'])
    plt.title(loc['Name'])
    plt.xticks(index, range(len(d)))
    plt.legend()

    plt.tight_layout()

    # save(name='pic_1_4_1', fmt='pdf')
    # save(name=(time.strftime("%Y-%m-%d_%H-%M-%S") if name =="" else name), fold=fold, fmt='png')
    if show: plt.show()
コード例 #2
0
ファイル: iterationResult.py プロジェクト: nikmedoed/pybinar
 def __init__(self, dist, XI2, Q, Qdiff, time):
     self.loc = localisation.loc(__file__)  # text for this file
     self.dist = dist
     self.xi2 = XI2
     self.Q = Q
     self.Qdiff = Qdiff
     self.time = time
     self.index = getIndex()
コード例 #3
0
 def __init__(self, generator, randomp):
     self.loc = localisation.loc(__file__) # text for this file
     self.randomp = randomp
     if generator == '0':
         self.generator = "python standart"
         self.rand = random.Random(x=randomp)
     elif generator == '1':
         self.generator = "our"
         self.rand = random.Random(x=randomp)
         # todo реализовать свой генератор
     else:
         self.generator = "special = " + generator
         self.rand = random.Random(x=randomp)
コード例 #4
0
    def __init__(self, cell, xyz=None):
        if xyz is None:
            xyz = [1, 1, 1]
        if type(cell) is supercell:
            pass
            raise NotImplementedError(
                "Now I can't to copy, use dc() (deepcopy)")
            #todo нормальное копирование
        else:
            self.loc = localisation.loc(__file__)  # text for this file
            self.cell = cell
            self.xyz = xyz
            self.atoms = [
            ]  # список атомов, в каждом указана связанная с ним ячейка
            self.cells = []  # позиции ячеек
            self.Cmul = reduce(lambda x, y: x * y, self.xyz)
            self.atomcountdict = dict()
            for i in cell.atomcountdict:
                self.atomcountdict[i] = self.cell.atomcountdict[i] * self.Cmul
            cellnum = 0
            self.atomcount = list(
                map(lambda a: [a[0], a[1] * self.Cmul], self.cell.atomcount))
            if cell.atoms == []: localisation.seterr(self.loc["CellNull"])

            atomsIndex = 0
            for x in range(self.xyz[0]):
                for y in range(self.xyz[1]):
                    for z in range(self.xyz[2]):
                        temp = []
                        for i in cell.atoms:
                            temp.append(
                                (i + [x, y, z]).setcell(cellnum).setRealPos(
                                    self.cell.cell_abc).setIndex(atomsIndex))
                            atomsIndex += 1
                        self.atoms.extend(temp)
                        cellnum += 1
                        self.cells.append([x, y, z])
            self.atoms.sort(key=lambda x: x.name)
            self.rawIndexTable = {
            }  # use this to find index in sorted array by initial index
            for i in range(len(self.atoms)):
                self.rawIndexTable[self.atoms[i].index] = i
            self.interestedAtoms = self.atoms
            self.atomTEMPcount = dict.fromkeys(self.cell.elements, 0)
            self.atomsBYelements = dict.fromkeys(self.cell.elements)

            for i in self.cell.elements:
                self.atomsBYelements[i] = list(
                    filter(lambda x: x.name == i, self.atoms))
コード例 #5
0
ファイル: parametrsPrint.py プロジェクト: nikmedoed/pybinar
 def __init__(self, param):
     loc = localisation.loc(__file__)  # text for this file
     [self.input,
      self.replication,
      self.cations_2sphere_cat,
      self.cations_2sphere_ani,
      self.cations_1sphere_cat,
      self.cations_1sphere_ani,
      self.min_x2,
      self.P_distrib,
      self.cations_conf,
      self.final_conf,
      self.GULP,
      self.distrib_diag
      ] = list(map(lambda x: x == "1", param))
コード例 #6
0
ファイル: atom.py プロジェクト: nikmedoed/pybinar
 def __init__(self, name, x, y=None, z=None, cell=0):
     if z:
         a = [x, y, z]
     else:
         if y: cell = y
         if x: a = x
         else:
             a = [0] * 3
     self.loc = localisation.loc(__file__)  # text for this file
     self.name = name
     self.initname = name
     self.pow = 0
     self.initpow = 0
     self.rule = -1
     self.element = element(self.name)
     self.pos = position(a)
     self.cell = cell
     self.neighbours = defaultdict(list)
     self.realpos = None
     self.index = None
     pass
コード例 #7
0
 def __init__(self):
     self.list = []
     self.trans = dict()
     self.loc = localisation.loc(__file__)
コード例 #8
0
ファイル: pybinar.py プロジェクト: nikmedoed/pybinar
            lang = param[1:]
        elif param[0] == "/":
            # "\\" in param or "/" in param
            outputfold = param[1:]
            # todo возможность указания полной директории для результатов
        else:
            input = param
            # todo файл с параметрами тоже брать откуда угодно, а не только из подпапки
    if outputfold == "":
        outputfold = input.split(".")[0] + " - results"

    if not os.path.exists(outputfold):
        os.mkdir(outputfold)

    localisation.setLoc(lang)  # object with all text
    loc = localisation.loc(__file__)  # text for this file

    print(loc["ParamIn"] + ": \x1b[36m" + input + "\x1b[0m")
    print(loc["ResOut"] + ": \x1b[36m" + outputfold + "\x1b[0m")
    print()

    # ======== read and prepare Data
    data = inData(input)
    os.chdir(outputfold)
    data.random.settime()
    outputfile = "00 - result.txt"

    # ======== Iterations

    start = time()
コード例 #9
0
ファイル: cell.py プロジェクト: nikmedoed/pybinar
 def __init__(self,
              name,
              file="NoneFile",
              cell_abc=[1, 1, 1],
              cell_ang=[90, 90, 90]):
     if type(name) is cell:
         self.loc = name.loc
         self.file = name.file
         # self.filemain = name.filemain
         self.cell_abc = name.cell_abc  # ab gamma, ac betta, cb alpha
         self.cell_ang = name.cell_ang
         self.cell_cos = list(
             map(lambda x: math.cos(x * math.pi / 180), self.cell_ang))
         self.elements = dc(name.elements)
         self.atomcountdict = name.atomcountdict
         self.atomcount = name.atomcount
         self.atoms = dc(name.atoms)
         self.atomsBYelements = dc(name.atomsBYelements)
     elif type(name) is list:
         self.file = file
         self.cell_abc = cell_abc
         self.cell_ang = cell_ang
         self.cell_cos = []
         self.elements = set()
         self.atoms = name
         self.loc = localisation.loc(__file__)
         # self.filemain = ""
         self.cell_cos = list(
             map(lambda x: math.cos(x * math.pi / 180), self.cell_ang))
         self.atomcountdict = dict()
         for i in name:
             if not (i.name in self.elements):
                 self.elements.add(i.name)
                 self.atomcountdict[i.name] = 0
             self.atomcountdict[i.name] += 1
         self.atomsBYelements = dict.fromkeys(self.elements)
         for i in self.elements:
             self.atomsBYelements[i] = list(
                 filter(lambda x: x.name == i, self.atoms))
     else:
         self.loc = localisation.loc(__file__)  # text for this file
         self.file = name
         # self.filemain = ""
         self.cell_abc = []
         self.cell_ang = []
         self.atoms = []
         main = True
         self.elements = set()
         self.atomcountdict = dict()
         with open(name, "r") as file:
             for i in file:
                 if "_cell_length" in i:
                     self.cell_abc.append(float(i.split()[1]))
                 if "_cell_angle" in i:
                     self.cell_ang.append(float(i.split()[1]))
                 if main:
                     if len(i.split()) > 3:
                         main = False
                 # if main:
                 #     self.filemain += i
                 if not main:
                     s = i.split()
                     if len(
                             s
                     ) > 0:  # проверить безопасность на примере кати 55к
                         if not (s[0] in self.elements):
                             self.elements.add(s[0])
                             self.atomcountdict[s[0]] = 0
                     self.atomcountdict[s[0]] += 1
                     self.atoms.append(
                         atom(s[0], s[1], s[2], s[3]).setpow(s[4]))
         self.cell_cos = list(
             map(lambda x: math.cos(x * math.pi / 180), self.cell_ang))
         self.atomcount = list(self.atomcountdict.items())
         self.atomcount.sort(key=lambda x: x[0])
         self.atoms.sort(key=lambda x: x.name)
         self.atomsBYelements = dict.fromkeys(self.elements)
         for i in self.elements:
             self.atomsBYelements[i] = list(
                 filter(lambda x: x.name == i, self.atoms))
コード例 #10
0
ファイル: parametrs.py プロジェクト: nikmedoed/pybinar
    def __init__(self, infile=""):
        self.loc = localisation.loc(__file__)  # text for this file
        self.rawparam = {}
        self.time = 0
        block = ""
        if infile == "":
            print(self.loc['InError'])
            raise Exception
        if not os.path.exists(infile):
            print(self.loc['InFileFalse'])
            raise Exception

        f = open(infile, "r", encoding="utf-8")
        for i in f:
            i = i.split("//")[0].strip()
            # print("n", i, "n")
            if len(i) > 0:
                # print(len(i))
                if i[len(i) - 1] == ":":
                    block = i[:len(i) - 1]
                    self.rawparam[block] = []
                else:
                    self.rawparam[block].append(i)

        conditions = self.rawparam['Сonditions']
        self.random = rand(conditions[1], conditions[2])
        self.insertionRules = []
        index = 0
        for k in conditions[3:]:
            i = k.replace(">", " ").replace("(", " ").replace(")", " ").split()
            if '.mol' in i[1]:
                molecules.molecules.readMol(i[1])
                i[1] = i[1]
            i[2] = float(i[2])
            if len(i) == 3:
                i.insert(2, 0)
            i[3] = int(i[3])
            i.append(index)
            index += 1
            self.insertionRules.append(i)

        const = self.rawparam['Сonstraints']
        self.timeLimit = int(const[0])*60 if not (":" in const[0]) else \
            sum(map(lambda x, y: int(x)*y, const[0].split(":"), [3600, 60, 1]))
        k = 1
        # self.sphere2 = float(const[1])
        self.sphere1 = float(const[k])
        k += 1
        self.x2toLess = "0" == const[k]
        k += 1
        self.x2stop = float(const[k])

        outp = self.rawparam["Output"]
        tmp = outp[0].split()
        self.x2fround_l = float(tmp[0])
        self.x2fround_r = float(
            tmp[1]) if len(tmp) > 1 else 0 if self.x2toLess else 100
        if self.x2fround_l > self.x2fround_r:
            self.x2fround_l = self.x2fround_r
            self.x2fround_r = float(tmp[0])

        self.Ntoprint = int(outp[1])
        self.pprint = printparam(outp[2:])
        self.atomsForChange = set(element(x[0]) for x in self.insertionRules) \
            .union(element(x[1]) for x in self.insertionRules)

        superDimensions = list(map(int, (conditions[0]).split()))
        chache = ".".join(infile.split(".")[:-1]) + ".pybinarchache"
        self.cell = cell(self.rawparam['Name'][0])
        print(self.loc['Readed'] + "\n")
        readed = False
        if os.path.exists(chache):
            print(self.loc['SuperFind'], "-", chache)
            try:
                with open(chache, "rb") as s:
                    cellTemp = pickle.load(s)
                    self.supercell = pickle.load(s)
                    self.supercell.cell = self.cell
                if (superDimensions == self.supercell.xyz) and (cellTemp
                                                                == self.cell):
                    print(self.loc['SuperOk'], chache)
                    readed = True
            except Exception as err:
                print(self.loc['SuperNo'], chache)
                print("Information:", err)

        if not readed:
            self.supercell = supercell(self.cell, superDimensions)
            self.supercell.addNeighbours(self.sphere1, self.atomsForChange)
            with open(chache, "wb") as s:
                pickle.dump(self.cell, s)
                pickle.dump(self.supercell, s)

        # количество соседей
        self.theoretical()
        print(self.loc['Prepared'])