def lengths(self): """ Lengths of axes of supercell. 晶格基向量长度。 """ with open(self.filename, "r") as f: for line in f: line = line.strip() if line.startswith("PBC "): line_list = str2list(line) return [float(l) for l in line_list[1: 4]] return None
def angles(self): """ Angels of axes of supercell in Degrees. 晶格基向量夹角(角度)。 """ with open(self.filename, "r") as f: for line in f: line = line.strip() if line.startswith("PBC "): line_list = str2list(line) return [float(l) for l in line_list[4: 7]] return None
def lengths(self): """ Lengths of axes of supercell. 晶格基向量长度。 """ with open(self.filename, "r") as f: for line in f: line = line.strip() if line.startswith("PBC "): line_list = str2list(line) return [float(l) for l in line_list[1:4]] return None
def angles(self): """ Angels of axes of supercell in Degrees. 晶格基向量夹角(角度)。 """ with open(self.filename, "r") as f: for line in f: line = line.strip() if line.startswith("PBC "): line_list = str2list(line) return [float(l) for l in line_list[4:7]] return None
def elements(self): """ Element name of all atom in lattice. 晶格中的所有元素种类名称。 """ with open(self.filename, "r") as f: collecting = False elements = [] for line in f: line = line.strip() if not collecting and line.startswith("PBC "): collecting = True elif collecting and line.startswith("end"): collecting = False return elements # Collect coordinates data. elif collecting: line_list = str2list(line) element = line_list[0] elements.append(element)
def coords_iterator(self): """ Return generator for Cartisan coordinates in arc file iteration. 返回每个轨迹的所有原子的笛卡尔坐标 """ with open(self.filename, "r") as f: collecting = False coords = [] for line in f: line = line.strip() if not collecting and line.startswith("PBC "): # NOTE: Use "PBC " to tell "PBC=" apart collecting = True elif collecting and line.startswith("end"): collecting = False yield np.array(coords) coords = [] # Collect coordinates data. elif collecting: line_list = str2list(line) coord = [float(c) for c in line_list[1: 4]] coords.append(coord)
idx = outcar.last_max_atom - 1 pos = pos[idx] forces = forces[idx] _logger.info("{:<15s}: {}".format("max force atom", outcar.last_max_atom)) _logger.info("{:<15s}: ({}, {}, {})".format("atom position", *pos)) _logger.info("{:<15s}: {}, {}, {}".format("forces", *forces)) _logger.info("{:<15s}: {}\n".format("total-force", outcar.last_max_force)) # Get fort.188 info. if os.path.exists('./fort.188'): with open('fort.188', 'r') as f: atom_info = f.readlines()[5] _logger.info("{:<10s}{:<10s}{:<15s}".format("Atom1", "Atom2", "DISTANCE")) _logger.info("-"*30) _logger.info("{:<10s}{:<10s}{:<15s}\n".format(*str2list(atom_info))) # Create .xsd file. if args.xsd: status, output = subprocess.getstatusoutput('ls *.xsd | head -1') if not output.endswith('.xsd'): _logger.info("No .xsd file in current directory.") sys.exit(1) xsd = XsdFile(filename=output) # modify atom color xsd.modify_color(atom_number=outcar.last_max_atom) jobname = output.split('.')[0] filename = jobname + '-force.xsd' xsd.tofile(filename=filename) _logger.info(filename + " has been created.")
force_info = outcar.atom_forces[max_num - 1, :] pos = force_info[:3].tolist() forces = force_info[3:].tolist() logging.info("{:<15s}: {}".format("max force atom", max_num)) logging.info("{:<15s}: ({}, {}, {})".format("atom position", *pos)) logging.info("{:<15s}: {}, {}, {}".format("forces", *forces)) logging.info("{:<15s}: {}\n".format("total-force", np.linalg.norm(forces))) # Get fort.188 info. if os.path.exists('./fort.188'): with open('fort.188', 'r') as f: atom_info = f.readlines()[5] logging.info("{:<10s}{:<10s}{:<15s}".format("Atom1", "Atom2", "DISTANCE")) logging.info("-" * 30) logging.info("{:<10s}{:<10s}{:<15s}\n".format(*str2list(atom_info))) # Create .xsd file. if args.xsd: status, output = commands.getstatusoutput('ls *.xsd | head -1') if not output.endswith('.xsd'): logging.info("No .xsd file in current directory.") sys.exit(1) xsd = XsdFile(filename=output) # modify atom color xsd.modify_color(atom_number=max_num) jobname = output.split('.')[0] filename = jobname + '-force.xsd' xsd.tofile(filename=filename) print filename + " has been created."
max_num = outcar.max_force_atom force_info = outcar.atom_forces[max_num-1, :] pos = force_info[: 3].tolist() forces = force_info[3:].tolist() print "\nmax force atom: %d" % max_num print " atom position: (%f, %f, %f)" % tuple(pos) print " forces: %f, %f, %f" % tuple(forces) print " total-force: %f\n" % np.linalg.norm(forces) # get fort.188 info if os.path.exists('./fort.188'): with open('fort.188', 'r') as f: atom_info = f.readlines()[5] print "%10s%10s%15s" % ('Atom1', 'Atom2', 'DISTANCE') print "-"*35 print "%10s%10s%15s\n" % tuple(str2list(atom_info)) # create .xsd file if '--xsd' in sys.argv: status, output = commands.getstatusoutput('ls *.xsd | head -1') if not output.endswith('.xsd'): print "No .xsd file in current directory." sys.exit(1) xsd = XsdFile(filename=output) # modify atom color xsd.modify_color(atom_number=max_num) jobname = output.split('.')[0] filename = jobname + '-force.xsd' xsd.tofile(filename=filename) print filename + " has been created."
a = XyzFile(filename=filename) b = PosCar(filename='POSCAR') #create new dir if not os.path.exists('./continue'): os.mkdir('./continue') if os.path.isfile('./fort.188'): fail = os.system("cp INCAR POTCAR KPOINTS fort.188 vasp.script ./continue") else: fail = os.system("cp INCAR POTCAR KPOINTS vasp.script ./continue") if not fail: #new fort.188 #change distance of 2 atoms with open('./continue/fort.188', 'r') as f: content_list = f.readlines() m, n, distance = str2list(content_list[5]) # atom number and distance x = a.data[int(m)-1, :] # atom coordinates y = a.data[int(n)-1, :] z = x - y #get new distance new_distance = np.dot(z, z)**0.5 newline = "%-5s%-5s%-10.6f\n" % (m, n, new_distance) content_list[5] = newline content_str = ''.join(content_list) #write new fort.188 with open('./continue/fort.188', 'w') as f: f.write(content_str) else: raise ContinueError('Failed to create continue dir.') #add new POSCAR
a = XyzFile(filename=filename) b = PosCar(filename='POSCAR') #create new dir if not os.path.exists('./continue'): os.mkdir('./continue') if os.path.isfile('./fort.188'): fail = os.system("cp INCAR POTCAR KPOINTS fort.188 vasp.script ./continue") else: fail = os.system("cp INCAR POTCAR KPOINTS vasp.script ./continue") if not fail: #new fort.188 #change distance of 2 atoms with open('./continue/fort.188', 'r') as f: content_list = f.readlines() m, n, distance = str2list(content_list[5]) # atom number and distance x = a.data[int(m) - 1, :] # atom coordinates y = a.data[int(n) - 1, :] z = x - y #get new distance new_distance = np.dot(z, z)**0.5 newline = "%-5s%-5s%-10.6f\n" % (m, n, new_distance) content_list[5] = newline content_str = ''.join(content_list) #write new fort.188 with open('./continue/fort.188', 'w') as f: f.write(content_str) else: raise ContinueError('Failed to create continue dir.') #add new POSCAR
# lattice basis info['bases'] = [] for i in range(3): vector = line2list(f.readline()) info['bases'].append(vector) info_nline = 7 info = {} with open(filename, 'r') as f: system = f.readline().strip() __read_info(info) # atom info info['atom_types'] = str2list(f.readline()) info['atoms_num'] = str2list(f.readline()) info['atom_numbers'] = [int(i) for i in info['atoms_num']] info['natom'] = sum(info['atom_numbers']) info['atom_names'] = [] for n, atom in zip(info['atoms_num'], info['atom_types']): info['atom_names'].extend([atom] * int(n)) while True: try: content = '' flush = f.readline().strip() if flush == system: __read_info(info) # update info # skip atom info f.readline()