def test_update_name(self): "Make sure we can update Name info." filename = path + "/h_top_c_fcc_far_noname.xsd" xsd = XsdFile(filename) xsd.update_name() for elem in xsd.tree.iter("SymmetrySystem"): name = elem.attrib["Name"] break self.assertTrue("E:" in name) self.assertTrue("F:" in name) self.assertTrue("M:" in name) self.assertTrue("P:" in name)
def test_bulk_construction(self): " Test XsdFile construction for a bulk. " filename = path + "/bulk.xsd" xsd = XsdFile(filename) # Check the default coordinate value for the Atom3d tag without XYZ. ref_origin_coord = [0.0, 0.0, 0.0] ret_origin_coord = xsd.data[0].tolist() self.assertListEqual(ref_origin_coord, ret_origin_coord) # Check atom info update in new xsd file. temp_file = "{}/temp.xsd".format(path) xsd.tofile(temp_file) tree = ET.parse(temp_file) for atom3d in tree.iter('Atom3d'): break self.assertEqual(atom3d.get('XYZ'), '0.0,0.0,0.0') os.remove(temp_file)
def test_get_name_info(self): " Make sure we can get correct info from Name property. " filename = path + "/h_top_c_fcc_far_noname.xsd" xsd = XsdFile(filename) self.assertEqual(xsd.force, 0.0) self.assertEqual(xsd.energy, 0.0) self.assertEqual(xsd.magnetism, 0.0) self.assertTrue(hasattr(xsd, "path"))
def read_xsd(): # Get xsd file for filename in os.listdir('.'): name_list = filename.split('.') if name_list[-1] == 'xsd': xsdname = name_list[0] xsd = XsdFile(filename) break content = 'XSD -->\n' content += " The xsdfile is : \033[31;1;4m%s\033[0m \n" %filename return content, xsd, xsdname
def test_construction_query(self): " Test OutCar construction and query functions. " filename = path + "/h_top_c_fcc_far.xsd" xsd = XsdFile(filename) # Check query functions. self.assertEqual(xsd.filename, filename) self.assertEqual(xsd.bases_const, 1.0) ref_bases = [[4.31035158, -2.48858265, 0.], [0., 4.97716529, 0.], [0., 0., 18.09575766]] self.assertListEqual(xsd.bases.tolist(), ref_bases) self.assertEqual(xsd.force, 0.048) self.assertEqual(xsd.energy, -100.896) self.assertEqual(xsd.magnetism, 8.25) self.assertTrue(hasattr(xsd, "path"))
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."
parser.add_argument("--ncpu", help="cpu number on each node") parser.add_argument("-q", "--queue", help="pbs queue type") # Add all possible arguments in INCAR file. if os.path.exists("INCAR"): incar = InCar() parameters = incar.pnames for parameter in parameters: help_info = "Set '{}' in INCAR".format(parameter) parser.add_argument("--{}".format(parameter), help=help_info) args = parser.parse_args() # Create POSCAR status, output = subprocess.getstatusoutput('ls *.xsd | head -1') xsd = XsdFile(filename=output) poscar_content = xsd.get_poscar_content(bases_const=1.0) with open('POSCAR', 'w') as f: f.write(poscar_content) # Create POTCAR potdir = r'/data/pot/vasp/potpaw_PBE2010/' # delete old POTCAR if os.path.exists('./POTCAR'): os.remove('./POTCAR') for elem in xsd.atoms: # if os.path.exists(potdir + elem + '_new/'): # potcar = potdir + elem + '_new/POTCAR' if os.path.exists(potdir + elem): potcar = potdir + elem + '/POTCAR' else:
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."
parser.add_argument("--ncpu", help="cpu number on each node") parser.add_argument("-q", "--queue", help="pbs queue type") # Add all possible arguments in INCAR file. if os.path.exists("INCAR"): incar = InCar() parameters = incar.pnames for parameter in parameters: help_info = "Set '{}' in INCAR".format(parameter) parser.add_argument("--{}".format(parameter), help=help_info) args = parser.parse_args() # Create POSCAR status, output = subprocess.getstatusoutput('ls *.xsd | head -1') xsd = XsdFile(filename=output) poscar_content = xsd.get_poscar_content(bases_const=1.0) with open('POSCAR', 'w') as f: f.write(poscar_content) # Create POTCAR potdir = r'/data/pot/vasp/potpaw_PBE2010/' # delete old POTCAR if os.path.exists('./POTCAR'): os.remove('./POTCAR') for elem in xsd.atom_types: # if os.path.exists(potdir + elem + '_new/'): # potcar = potdir + elem + '_new/POTCAR' if os.path.exists(potdir + elem): potcar = potdir + elem + '/POTCAR' else:
_logger.info("{:<15s}: ({}, {}, {})".format("atom position", *poses[i])) _logger.info("{:<15s}: {}, {}, {}".format("forces", *forces[i])) else: _logger.info("Cannot get the max force in %s." % x) _logger.info("Atoms not optimized >>> \n" + " " * 24 + "%s" % ([i + 1 for i in bad_ids])) # 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.")
parser = argparse.ArgumentParser() parser.add_argument('-x', '--xsd', \ default='default.xsd', help='xsd File') parser.add_argument('-g', '--gen', \ default='geo_in.gen', help='Gen Format File Name') args = parser.parse_args() # read xsd and get fixes if args.xsd == 'default.xsd': for fname in os.listdir('.'): name_list = fname.split('.') if name_list[-1] == 'xsd': xsdname = name_list[0] xsd = XsdFile(fname) break else: xsd = XsdFile(args.xsd) symbol_dict = {} for i, symbol in enumerate(xsd.atom_types): symbol_dict[symbol] = i + 1 symbols = [] for num, sym in zip(xsd.atom_numbers, xsd.atom_types): symbols.extend([sym] * num) content = (' {:<8d} {:<s}\n').format(xsd.natom, 'F') content += ('{:>4s}' * len(xsd.atom_types) + '\n').format(*xsd.atom_types) for i, (sym, coord) in enumerate(zip(symbols, xsd.data)):