def test_forces(self): " Make sure we can get correct forces data." # {{{ filename = path + "/OUTCAR" poscar = path + "/POSCAR" outcar = OutCar(filename=filename, poscar=poscar) coords, forces = outcar.forces() ref_coords = [[1.78441, 0.85618, 2.29204], [0.16369, 0.85618, 4.56647], [0.97405, -0.5474, 0.0], [0.97405, -0.5474, 6.88358], [4.21548, -0.5474, 2.29204], [2.59476, -0.5474, 4.56647], [3.40512, -1.95098, 0.0], [3.40512, -1.95098, 6.88358], [6.64655, -1.95098, 2.29204], [5.02584, -1.95098, 4.56647], [5.83619, -3.35456, 0.0], [5.83619, -3.35456, 6.88358], [1.78441, 3.66334, 2.29204], [0.16369, 3.66334, 4.56647], [0.97405, 2.25976, 0.0], [0.97405, 2.25976, 6.88358], [4.21548, 2.25976, 2.29204], [2.59476, 2.25976, 4.56647], [3.40512, 0.85618, 0.0], [3.40512, 0.85618, 6.88358], [6.64655, 0.85618, 2.29204], [5.02584, 0.85618, 4.56647], [5.83619, -0.5474, 0.0], [5.83619, -0.5474, 6.88358], [1.78441, 6.4705, 2.29204], [0.16369, 6.4705, 4.56647], [0.97405, 5.06692, 0.0], [0.97405, 5.06692, 6.88358], [4.21548, 5.06692, 2.29204], [2.59476, 5.06692, 4.56647], [3.40512, 3.66334, 0.0], [3.40512, 3.66334, 6.88358], [6.64655, 3.66334, 2.29204], [5.02584, 3.66334, 4.56647], [5.83619, 2.25976, 0.0], [5.83619, 2.25976, 6.88358]] ref_forces = [[0.0, -0.0, 0.136895], [0.0, 0.0, 0.008464], [0.0, -0.0, -0.099126], [-0.0, -0.0, -0.046234], [0.0, -0.0, 0.136895], [-0.0, 0.0, 0.008464], [0.0, -0.0, -0.099126], [-0.0, -0.0, -0.046234], [0.0, -0.0, 0.136895], [-0.0, -0.0, 0.008464], [0.0, -0.0, -0.099126], [-0.0, -0.0, -0.046234], [0.0, -0.0, 0.136895], [0.0, -0.0, 0.008464], [0.0, -0.0, -0.099126], [-0.0, -0.0, -0.046234], [0.0, -0.0, 0.136895], [-0.0, 0.0, 0.008464], [0.0, -0.0, -0.099126], [-0.0, 0.0, -0.046234], [0.0, -0.0, 0.136895], [-0.0, 0.0, 0.008464], [0.0, -0.0, -0.099126], [-0.0, -0.0, -0.046234], [0.0, -0.0, 0.136895], [0.0, -0.0, 0.008464], [0.0, -0.0, -0.099126], [-0.0, 0.0, -0.046234], [0.0, -0.0, 0.136895], [-0.0, 0.0, 0.008464], [0.0, -0.0, -0.099126], [-0.0, 0.0, -0.046234], [0.0, -0.0, 0.136895], [0.0, 0.0, 0.008464], [0.0, -0.0, -0.099126], [-0.0, 0.0, -0.046234]] ret_coords, ret_forces = outcar.forces() self.assertListEqual(ref_coords, ret_coords) self.assertListEqual(ref_forces, ret_forces)
def test_fmax(self): " Make sure we can get correct max forces. " filename = path + "/OUTCAR" poscar = path + "/POSCAR" outcar = OutCar(filename=filename, poscar=poscar) coords, forces = outcar.forces() ret_index, ret_max_force = outcar.fmax(forces) ref_index = 4 ref_max_force = [-0.0, -0.0, -0.046234] self.assertEqual(ret_index, ref_index) self.assertListEqual(ret_max_force, ref_max_force)
import numpy as np from vaspy.iter import OutCar from vaspy.matstudio import XsdFile from vaspy.functions import str2list _logger = logging.getLogger("vaspy.script") # Set arguments parser. parser = argparse.ArgumentParser() parser.add_argument("--xsd", help="create MaterStudio .xsd file", action="store_true") args = parser.parse_args() outcar = OutCar() pos, forces = outcar.forces(-1) 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)
from vaspy.atomco import PosCar from vaspy.iter import OutCar from vaspy.matstudio import XsdFile from vaspy.functions import str2list _logger = logging.getLogger("vaspy.script") # Set arguments parser. parser = argparse.ArgumentParser() parser.add_argument("--xsd", help="create MaterStudio .xsd file", action="store_true") args = parser.parse_args() outcar = OutCar() poses, forces = outcar.forces(-1) poscar = PosCar() tfs = poscar.tf incar = InCar() #print(incar.paras) EDIFFG = incar.get_pvalue('EDIFFG') #EDIFFG = 0.05 bad_ids = [] max_idx = [-1, -1, -1] max_force = [0., 0., 0.] for i, (pos, force, tf) in enumerate(zip(poses, forces, tfs)): for j, (c, f) in enumerate(zip(tf, force)): if c == 'T':