1"""Phonopy input and command option tools.""" 2# Copyright (C) 2011 Atsushi Togo 3# All rights reserved. 4# 5# This file is part of phonopy. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 11# * Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 14# * Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in 16# the documentation and/or other materials provided with the 17# distribution. 18# 19# * Neither the name of the phonopy project nor the names of its 20# contributors may be used to endorse or promote products derived 21# from this software without specific prior written permission. 22# 23# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 29# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 33# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34# POSSIBILITY OF SUCH DAMAGE. 35 36import sys 37import numpy as np 38 39 40def fracval(frac): 41 """Return floating point value from rational.""" 42 if frac.find('/') == -1: 43 return float(frac) 44 else: 45 x = frac.split('/') 46 return float(x[0]) / float(x[1]) 47 48 49class Settings(object): 50 """Phonopy settings container. 51 52 This works almost like a dictionary. 53 Method names without 'set_' and 'get_' and keys of self._v have to be same. 54 55 """ 56 57 _default = { 58 'band_indices': None, 59 'band_paths': None, 60 'band_points': None, 61 'cell_filename': None, 62 'chemical_symbols': None, 63 'cutoff_frequency': None, 64 'displacement_distance': None, 65 'dm_decimals': None, 66 'calculator': None, 67 'create_displacements': False, 68 'fc_calculator': None, 69 'fc_calculator_options': None, 70 'fc_decimals': None, 71 'fc_symmetry': False, 72 'frequency_pitch': None, 73 'frequency_conversion_factor': None, 74 'frequency_scale_factor': None, 75 'group_velocity_delta_q': None, 76 'hdf5_compression': 'gzip', 77 'is_band_const_interval': False, 78 'is_diagonal_displacement': True, 79 'is_eigenvectors': False, 80 'is_mesh_symmetry': True, 81 'is_nac': False, 82 'is_plusminus_displacement': 'auto', 83 'is_symmetry': True, 84 'is_tetrahedron_method': True, 85 'is_time_reversal_symmetry': True, 86 'is_trigonal_displacement': False, 87 'magnetic_moments': None, 88 'masses': None, 89 'mesh_numbers': None, 90 'nac_method': None, 91 'nac_q_direction': None, 92 'num_frequency_points': None, 93 'primitive_matrix': None, 94 'qpoints': None, 95 'read_qpoints': False, 96 'sigma': None, 97 'supercell_matrix': None, 98 'symmetry_tolerance': None, 99 'temperatures': None, 100 'max_temperature': 1000, 101 'min_temperature': 0, 102 'temperature_step': 10 103 } 104 105 def __init__(self, default=None): 106 """Init method. 107 108 Note 109 ---- 110 self.default is used in inherited classes. 111 112 """ 113 self.default = Settings._default.copy() 114 if default is not None: 115 self.default.update(default) 116 self._v = self.default.copy() 117 118 def __getattr__(self, attr): 119 """Return dict value of key attr.""" 120 return self._v[attr] 121 122 def set_band_paths(self, val): 123 self._v['band_paths'] = val 124 125 def set_band_points(self, val): 126 self._v['band_points'] = val 127 128 def set_band_indices(self, val): 129 self._v['band_indices'] = val 130 131 def set_cell_filename(self, val): 132 self._v['cell_filename'] = val 133 134 def set_chemical_symbols(self, val): 135 self._v['chemical_symbols'] = val 136 137 def set_create_displacements(self, val): 138 self._v['create_displacements'] = val 139 140 def set_cutoff_frequency(self, val): 141 self._v['cutoff_frequency'] = val 142 143 def set_dm_decimals(self, val): 144 self._v['dm_decimals'] = val 145 146 def set_displacement_distance(self, val): 147 self._v['displacement_distance'] = val 148 149 def set_calculator(self, val): 150 self._v['calculator'] = val 151 152 def set_fc_calculator(self, val): 153 self._v['fc_calculator'] = val 154 155 def set_fc_calculator_options(self, val): 156 self._v['fc_calculator_options'] = val 157 158 def set_fc_symmetry(self, val): 159 self._v['fc_symmetry'] = val 160 161 def set_fc_decimals(self, val): 162 self._v['fc_decimals'] = val 163 164 def set_frequency_conversion_factor(self, val): 165 self._v['frequency_conversion_factor'] = val 166 167 def set_frequency_pitch(self, val): 168 self._v['frequency_pitch'] = val 169 170 def set_frequency_scale_factor(self, val): 171 self._v['frequency_scale_factor'] = val 172 173 def set_group_velocity_delta_q(self, val): 174 self._v['group_velocity_delta_q'] = val 175 176 def set_hdf5_compression(self, val): 177 self._v['hdf5_compression'] = val 178 179 def set_is_band_const_interval(self, val): 180 self._v['is_band_const_interval'] = val 181 182 def set_is_diagonal_displacement(self, val): 183 self._v['is_diagonal_displacement'] = val 184 185 def set_is_eigenvectors(self, val): 186 self._v['is_eigenvectors'] = val 187 188 def set_is_mesh_symmetry(self, val): 189 self._v['is_mesh_symmetry'] = val 190 191 def set_is_nac(self, val): 192 self._v['is_nac'] = val 193 194 def set_is_plusminus_displacement(self, val): 195 self._v['is_plusminus_displacement'] = val 196 197 def set_is_tetrahedron_method(self, val): 198 self._v['is_tetrahedron_method'] = val 199 200 def set_is_trigonal_displacement(self, val): 201 self._v['is_trigonal_displacement'] = val 202 203 def set_is_symmetry(self, val): 204 self._v['is_symmetry'] = val 205 206 def set_magnetic_moments(self, val): 207 self._v['magnetic_moments'] = val 208 209 def set_masses(self, val): 210 self._v['masses'] = val 211 212 def set_max_temperature(self, val): 213 self._v['max_temperature'] = val 214 215 def set_mesh_numbers(self, val): 216 self._v['mesh_numbers'] = val 217 218 def set_min_temperature(self, val): 219 self._v['min_temperature'] = val 220 221 def set_nac_method(self, val): 222 self._v['nac_method'] = val 223 224 def set_nac_q_direction(self, val): 225 self._v['nac_q_direction'] = val 226 227 def set_num_frequency_points(self, val): 228 self._v['num_frequency_points'] = val 229 230 def set_primitive_matrix(self, val): 231 self._v['primitive_matrix'] = val 232 233 def set_qpoints(self, val): 234 self._v['qpoints'] = val 235 236 def set_read_qpoints(self, val): 237 self._v['read_qpoints'] = val 238 239 def set_sigma(self, val): 240 self._v['sigma'] = val 241 242 def set_supercell_matrix(self, val): 243 self._v['supercell_matrix'] = val 244 245 def set_symmetry_tolerance(self, val): 246 self._v['symmetry_tolerance'] = val 247 248 def set_temperatures(self, val): 249 self._v['temperatures'] = val 250 251 def set_temperature_step(self, val): 252 self._v['temperature_step'] = val 253 254 def set_is_time_reversal_symmetry(self, val): 255 self._v['is_time_reversal_symmetry'] = val 256 257 258# Parse phonopy setting filen 259class ConfParser(object): 260 """Phonopy conf file parser.""" 261 262 def __init__(self, filename=None, args=None): 263 """Init method.""" 264 self._confs = {} 265 self._parameters = {} 266 self._args = args 267 self._filename = filename 268 269 @property 270 def confs(self): 271 return self._confs 272 273 def get_configures(self): 274 return self.confs 275 276 @property 277 def settings(self): 278 return self._settings 279 280 def get_settings(self): 281 return self.settings 282 283 def setting_error(self, message): 284 print(message) 285 print("Please check the setting tags and options.") 286 sys.exit(1) 287 288 def read_file(self): 289 file = open(self._filename, 'r') 290 is_continue = False 291 left = None 292 293 for line in file: 294 if line.strip() == '': 295 is_continue = False 296 continue 297 298 if line.strip()[0] == '#': 299 is_continue = False 300 continue 301 302 if is_continue and left is not None: 303 self._confs[left] += line.strip() 304 self._confs[left] = self._confs[left].replace('+++', ' ') 305 is_continue = False 306 307 if line.find('=') != -1: 308 left, right = [x.strip() for x in line.split('=')] 309 self._confs[left.lower()] = right 310 311 if line.find('+++') != -1: 312 is_continue = True 313 314 def read_options(self): 315 arg_list = vars(self._args) 316 if 'band_indices' in arg_list: 317 band_indices = self._args.band_indices 318 if band_indices is not None: 319 if type(band_indices) is list: 320 self._confs['band_indices'] = " ".join(band_indices) 321 else: 322 self._confs['band_indices'] = band_indices 323 324 if 'band_paths' in arg_list: 325 if self._args.band_paths is not None: 326 if type(self._args.band_paths) is list: 327 self._confs['band'] = " ".join(self._args.band_paths) 328 else: 329 self._confs['band'] = self._args.band_paths 330 331 if 'band_points' in arg_list: 332 if self._args.band_points is not None: 333 self._confs['band_points'] = self._args.band_points 334 335 if 'cell_filename' in arg_list: 336 if self._args.cell_filename is not None: 337 self._confs['cell_filename'] = self._args.cell_filename 338 339 if 'cutoff_frequency' in arg_list: 340 if self._args.cutoff_frequency: 341 self._confs['cutoff_frequency'] = self._args.cutoff_frequency 342 343 if 'displacement_distance' in arg_list: 344 if self._args.displacement_distance: 345 self._confs['displacement_distance'] = \ 346 self._args.displacement_distance 347 348 if 'dynamical_matrix_decimals' in arg_list: 349 if self._args.dynamical_matrix_decimals: 350 self._confs['dm_decimals'] = \ 351 self._args.dynamical_matrix_decimals 352 353 if 'calculator' in arg_list: 354 if self._args.calculator: 355 self._confs['calculator'] = self._args.calculator 356 357 if 'fc_calculator' in arg_list: 358 if self._args.fc_calculator: 359 self._confs['fc_calculator'] = self._args.fc_calculator 360 361 if 'fc_calculator_options' in arg_list: 362 fc_calc_opt = self._args.fc_calculator_options 363 if fc_calc_opt: 364 self._confs['fc_calculator_options'] = fc_calc_opt 365 366 if 'fc_symmetry' in arg_list: 367 if self._settings.default['fc_symmetry']: 368 if self._args.fc_symmetry is False: 369 self._confs['fc_symmetry'] = '.false.' 370 else: 371 if self._args.fc_symmetry: 372 self._confs['fc_symmetry'] = '.true.' 373 374 if 'force_constants_decimals' in arg_list: 375 if self._args.force_constants_decimals: 376 self._confs['fc_decimals'] = \ 377 self._args.force_constants_decimals 378 379 if 'fpitch' in arg_list: 380 if self._args.fpitch: 381 self._confs['fpitch'] = self._args.fpitch 382 383 if 'frequency_conversion_factor' in arg_list: 384 freq_factor = self._args.frequency_conversion_factor 385 if freq_factor: 386 self._confs['frequency_conversion_factor'] = freq_factor 387 388 if 'frequency_scale_factor' in arg_list: 389 freq_scale = self._args.frequency_scale_factor 390 if freq_scale is not None: 391 self._confs['frequency_scale_factor'] = freq_scale 392 393 if 'gv_delta_q' in arg_list: 394 if self._args.gv_delta_q: 395 self._confs['gv_delta_q'] = self._args.gv_delta_q 396 397 if 'hdf5_compression' in arg_list: 398 if self._args.hdf5_compression: 399 self._confs['hdf5_compression'] = self._args.hdf5_compression 400 401 if 'is_band_const_interval' in arg_list: 402 if self._args.is_band_const_interval: 403 self._confs['band_const_interval'] = '.true.' 404 405 if 'is_displacement' in arg_list: 406 if self._args.is_displacement: 407 self._confs['create_displacements'] = '.true.' 408 409 if 'is_eigenvectors' in arg_list: 410 if self._args.is_eigenvectors: 411 self._confs['eigenvectors'] = '.true.' 412 413 if 'is_nac' in arg_list: 414 if self._settings.default['is_nac']: # Check default settings 415 if self._args.is_nac is False: 416 self._confs['nac'] = '.false.' 417 else: 418 if self._args.is_nac: 419 self._confs['nac'] = '.true.' 420 421 if 'is_nodiag' in arg_list: 422 if self._args.is_nodiag: 423 self._confs['diag'] = '.false.' 424 425 if 'is_nomeshsym' in arg_list: 426 if self._args.is_nomeshsym: 427 self._confs['mesh_symmetry'] = '.false.' 428 429 if 'is_nosym' in arg_list: 430 if self._args.is_nosym: 431 self._confs['symmetry'] = '.false.' 432 433 if 'is_plusminus_displacements' in arg_list: 434 if self._args.is_plusminus_displacements: 435 self._confs['pm'] = '.true.' 436 437 if 'is_trigonal_displacements' in arg_list: 438 if self._args.is_trigonal_displacements: 439 self._confs['trigonal'] = '.true.' 440 441 if 'masses' in arg_list: 442 if self._args.masses is not None: 443 if type(self._args.masses) is list: 444 self._confs['mass'] = " ".join(self._args.masses) 445 else: 446 self._confs['mass'] = self._args.masses 447 448 if 'magmoms' in arg_list: 449 if self._args.magmoms is not None: 450 if type(self._args.magmoms) is list: 451 self._confs['magmom'] = " ".join(self._args.magmoms) 452 else: 453 self._confs['magmom'] = self._args.magmoms 454 455 if 'mesh_numbers' in arg_list: 456 mesh = self._args.mesh_numbers 457 if mesh is not None: 458 if type(mesh) is list: 459 self._confs['mesh_numbers'] = " ".join(mesh) 460 else: 461 self._confs['mesh_numbers'] = mesh 462 463 if 'num_frequency_points' in arg_list: 464 opt_num_freqs = self._args.num_frequency_points 465 if opt_num_freqs: 466 self._confs['num_frequency_points'] = opt_num_freqs 467 468 # For backword compatibility 469 if 'primitive_axis' in arg_list: 470 if self._args.primitive_axis is not None: 471 if type(self._args.primitive_axis) is list: 472 primitive_axes = " ".join(self._args.primitive_axis) 473 self._confs['primitive_axes'] = primitive_axes 474 else: 475 self._confs['primitive_axes'] = self._args.primitive_axis 476 477 if 'primitive_axes' in arg_list: 478 if self._args.primitive_axes: 479 if type(self._args.primitive_axes) is list: 480 primitive_axes = " ".join(self._args.primitive_axes) 481 self._confs['primitive_axes'] = primitive_axes 482 else: 483 self._confs['primitive_axes'] = self._args.primitive_axes 484 485 if 'supercell_dimension' in arg_list: 486 dim = self._args.supercell_dimension 487 if dim is not None: 488 if type(dim) is list: 489 self._confs['dim'] = " ".join(dim) 490 else: 491 self._confs['dim'] = dim 492 493 if 'qpoints' in arg_list: 494 if self._args.qpoints is not None: 495 if type(self._args.qpoints) is list: 496 self._confs['qpoints'] = " ".join(self._args.qpoints) 497 else: 498 self._confs['qpoints'] = self._args.qpoints 499 500 if 'nac_q_direction' in arg_list: 501 q_dir = self._args.nac_q_direction 502 if q_dir is not None: 503 if type(q_dir) is list: 504 self._confs['q_direction'] = " ".join(q_dir) 505 else: 506 self._confs['q_direction'] = q_dir 507 508 if 'nac_method' in arg_list: 509 if self._args.nac_method is not None: 510 self._confs['nac_method'] = self._args.nac_method 511 512 if 'read_qpoints' in arg_list: 513 if self._args.read_qpoints: 514 self._confs['read_qpoints'] = '.true.' 515 516 if 'sigma' in arg_list: 517 if self._args.sigma is not None: 518 if type(self._args.sigma) is list: 519 self._confs['sigma'] = " ".join(self._args.sigma) 520 else: 521 self._confs['sigma'] = self._args.sigma 522 523 if 'symmetry_tolerance' in arg_list: 524 if self._args.symmetry_tolerance: 525 symtol = self._args.symmetry_tolerance 526 self._confs['symmetry_tolerance'] = symtol 527 528 if 'temperature' in arg_list: 529 if self._args.temperature is not None: 530 self._confs['temperature'] = self._args.temperature 531 532 if 'temperatures' in arg_list: 533 if self._args.temperatures is not None: 534 self._confs['temperatures'] = " ".join(self._args.temperatures) 535 536 if 'tmax' in arg_list: 537 if self._args.tmax: 538 self._confs['tmax'] = self._args.tmax 539 540 if 'tmin' in arg_list: 541 if self._args.tmin: 542 self._confs['tmin'] = self._args.tmin 543 544 if 'tstep' in arg_list: 545 if self._args.tstep: 546 self._confs['tstep'] = self._args.tstep 547 548 from phonopy.interface.calculator import get_interface_mode 549 calculator = get_interface_mode(arg_list) 550 if calculator: 551 self._confs['calculator'] = calculator 552 553 if 'use_alm' in arg_list: 554 if self._args.use_alm: 555 self._confs['fc_calculator'] = 'alm' 556 557 if 'use_hiphive' in arg_list: 558 if self._args.use_hiphive: 559 self._confs['fc_calculator'] = 'hiphive' 560 561 def parse_conf(self): 562 confs = self._confs 563 564 for conf_key in confs.keys(): 565 if conf_key == 'band_indices': 566 vals = [] 567 for sum_set in confs['band_indices'].split(','): 568 vals.append([int(x) - 1 for x in sum_set.split()]) 569 self.set_parameter('band_indices', vals) 570 571 if conf_key == 'cell_filename': 572 self.set_parameter('cell_filename', confs['cell_filename']) 573 574 if conf_key == 'create_displacements': 575 if confs['create_displacements'].lower() == '.true.': 576 self.set_parameter('create_displacements', True) 577 elif confs['create_displacements'].lower() == '.false.': 578 self.set_parameter('create_displacements', False) 579 580 if conf_key == 'dim': 581 matrix = [int(x) for x in confs['dim'].split()] 582 if len(matrix) == 9: 583 matrix = np.array(matrix).reshape(3, 3) 584 elif len(matrix) == 3: 585 matrix = np.diag(matrix) 586 else: 587 self.setting_error( 588 "Number of elements of DIM tag has to be 3 or 9.") 589 590 if matrix.shape == (3, 3): 591 if np.linalg.det(matrix) < 1: 592 self.setting_error( 593 'Determinant of supercell matrix has to be ' 594 'positive.') 595 else: 596 self.set_parameter('supercell_matrix', matrix) 597 598 if conf_key in ('primitive_axis', 'primitive_axes'): 599 if confs[conf_key].strip().lower() == 'auto': 600 self.set_parameter('primitive_axes', 'auto') 601 elif confs[conf_key].strip().upper() in ( 602 'P', 'F', 'I', 'A', 'C', 'R'): 603 self.set_parameter('primitive_axes', 604 confs[conf_key].strip().upper()) 605 elif not len(confs[conf_key].split()) == 9: 606 self.setting_error( 607 "Number of elements in %s has to be 9." % 608 conf_key.upper()) 609 else: 610 p_axis = [] 611 for x in confs[conf_key].split(): 612 p_axis.append(fracval(x)) 613 p_axis = np.array(p_axis).reshape(3, 3) 614 if np.linalg.det(p_axis) < 1e-8: 615 self.setting_error( 616 "%s has to have positive determinant." % 617 conf_key.upper()) 618 self.set_parameter('primitive_axes', p_axis) 619 620 if conf_key == 'mass': 621 self.set_parameter( 622 'mass', 623 [float(x) for x in confs['mass'].split()]) 624 625 if conf_key == 'magmom': 626 self.set_parameter( 627 'magmom', 628 [float(x) for x in confs['magmom'].split()]) 629 630 if conf_key == 'atom_name': 631 self.set_parameter( 632 'atom_name', 633 [x.capitalize() for x in confs['atom_name'].split()]) 634 635 if conf_key == 'displacement_distance': 636 self.set_parameter('displacement_distance', 637 float(confs['displacement_distance'])) 638 639 if conf_key == 'diag': 640 if confs['diag'].lower() == '.false.': 641 self.set_parameter('diag', False) 642 elif confs['diag'].lower() == '.true.': 643 self.set_parameter('diag', True) 644 645 if conf_key == 'pm': 646 if confs['pm'].lower() == '.false.': 647 self.set_parameter('pm_displacement', False) 648 elif confs['pm'].lower() == '.true.': 649 self.set_parameter('pm_displacement', True) 650 651 if conf_key == 'trigonal': 652 if confs['trigonal'].lower() == '.false.': 653 self.set_parameter('is_trigonal_displacement', False) 654 elif confs['trigonal'].lower() == '.true.': 655 self.set_parameter('is_trigonal_displacement', True) 656 657 if conf_key == 'eigenvectors': 658 if confs['eigenvectors'].lower() == '.false.': 659 self.set_parameter('is_eigenvectors', False) 660 elif confs['eigenvectors'].lower() == '.true.': 661 self.set_parameter('is_eigenvectors', True) 662 663 if conf_key == 'nac': 664 if confs['nac'].lower() == '.false.': 665 self.set_parameter('is_nac', False) 666 elif confs['nac'].lower() == '.true.': 667 self.set_parameter('is_nac', True) 668 669 if conf_key == 'symmetry': 670 if confs['symmetry'].lower() == '.false.': 671 self.set_parameter('is_symmetry', False) 672 self.set_parameter('is_mesh_symmetry', False) 673 elif confs['symmetry'].lower() == '.true.': 674 self.set_parameter('is_symmetry', True) 675 676 if conf_key == 'mesh_symmetry': 677 if confs['mesh_symmetry'].lower() == '.false.': 678 self.set_parameter('is_mesh_symmetry', False) 679 elif confs['mesh_symmetry'].lower() == '.true.': 680 self.set_parameter('is_mesh_symmetry', True) 681 682 if conf_key == 'calculator': 683 self.set_parameter('calculator', confs['calculator']) 684 685 if conf_key == 'fc_calculator': 686 self.set_parameter('fc_calculator', confs['fc_calculator']) 687 688 if conf_key == 'fc_calculator_options': 689 self.set_parameter('fc_calculator_options', 690 confs['fc_calculator_options']) 691 692 if conf_key == 'fc_symmetry': 693 if confs['fc_symmetry'].lower() == '.false.': 694 self.set_parameter('fc_symmetry', False) 695 elif confs['fc_symmetry'].lower() == '.true.': 696 self.set_parameter('fc_symmetry', True) 697 698 if conf_key == 'fc_decimals': 699 self.set_parameter('fc_decimals', confs['fc_decimals']) 700 701 if conf_key == 'dm_decimals': 702 self.set_parameter('dm_decimals', confs['dm_decimals']) 703 704 if conf_key in ['mesh_numbers', 'mp', 'mesh']: 705 vals = [x for x in confs[conf_key].split()] 706 if len(vals) == 1: 707 self.set_parameter('mesh_numbers', float(vals[0])) 708 elif len(vals) < 3: 709 self.setting_error("Mesh numbers are incorrectly set.") 710 else: 711 self.set_parameter('mesh_numbers', 712 [int(x) for x in vals[:3]]) 713 714 if conf_key == 'band_points': 715 self.set_parameter('band_points', int(confs['band_points'])) 716 717 if conf_key == 'band_const_interval': 718 if confs['band_const_interval'].lower() == '.false.': 719 self.set_parameter('is_band_const_interval', False) 720 elif confs['band_const_interval'].lower() == '.true.': 721 self.set_parameter('is_band_const_interval', True) 722 723 if conf_key == 'band': 724 bands = [] 725 if confs['band'].strip().lower() == 'auto': 726 self.set_parameter('band_paths', 'auto') 727 else: 728 for section in confs['band'].split(','): 729 points = [fracval(x) for x in section.split()] 730 if len(points) % 3 != 0 or len(points) < 6: 731 self.setting_error("BAND is incorrectly set.") 732 break 733 bands.append(np.array(points).reshape(-1, 3)) 734 self.set_parameter('band_paths', bands) 735 736 if conf_key == 'qpoints': 737 if confs['qpoints'].lower() == '.true.': 738 self.set_parameter('read_qpoints', True) 739 elif confs['qpoints'].lower() == '.false.': 740 self.set_parameter('read_qpoints', False) 741 else: 742 vals = [fracval(x) for x in confs['qpoints'].split()] 743 if len(vals) == 0 or len(vals) % 3 != 0: 744 self.setting_error("Q-points are incorrectly set.") 745 else: 746 self.set_parameter('qpoints', 747 list(np.reshape(vals, (-1, 3)))) 748 749 if conf_key == 'read_qpoints': 750 if confs['read_qpoints'].lower() == '.false.': 751 self.set_parameter('read_qpoints', False) 752 elif confs['read_qpoints'].lower() == '.true.': 753 self.set_parameter('read_qpoints', True) 754 755 if conf_key == 'nac_method': 756 self.set_parameter('nac_method', confs['nac_method'].lower()) 757 758 if conf_key == 'q_direction': 759 q_direction = [fracval(x) 760 for x in confs['q_direction'].split()] 761 if len(q_direction) < 3: 762 self.setting_error("Number of elements of q_direction " 763 "is less than 3") 764 else: 765 self.set_parameter('nac_q_direction', q_direction) 766 767 if conf_key == 'frequency_conversion_factor': 768 val = float(confs['frequency_conversion_factor']) 769 self.set_parameter('frequency_conversion_factor', val) 770 771 if conf_key == 'frequency_scale_factor': 772 self.set_parameter('frequency_scale_factor', 773 float(confs['frequency_scale_factor'])) 774 775 if conf_key == 'fpitch': 776 val = float(confs['fpitch']) 777 self.set_parameter('fpitch', val) 778 779 if conf_key == 'num_frequency_points': 780 val = int(confs['num_frequency_points']) 781 self.set_parameter('num_frequency_points', val) 782 783 if conf_key == 'cutoff_frequency': 784 val = float(confs['cutoff_frequency']) 785 self.set_parameter('cutoff_frequency', val) 786 787 if conf_key == 'sigma': 788 vals = [float(x) for x in str(confs['sigma']).split()] 789 if len(vals) == 1: 790 self.set_parameter('sigma', vals[0]) 791 else: 792 self.set_parameter('sigma', vals) 793 794 if conf_key == 'tetrahedron': 795 if confs['tetrahedron'].lower() == '.false.': 796 self.set_parameter('is_tetrahedron_method', False) 797 if confs['tetrahedron'].lower() == '.true.': 798 self.set_parameter('is_tetrahedron_method', True) 799 800 if conf_key == 'symmetry_tolerance': 801 val = float(confs['symmetry_tolerance']) 802 self.set_parameter('symmetry_tolerance', val) 803 804 # For multiple T values. 805 if conf_key == 'temperatures': 806 vals = [fracval(x) for x in confs['temperatures'].split()] 807 if len(vals) < 1: 808 self.setting_error("Temperatures are incorrectly set.") 809 else: 810 self.set_parameter('temperatures', vals) 811 812 # For single T value. 813 if conf_key == 'temperature': 814 self.set_parameter('temperatures', [confs['temperature'], ]) 815 816 if conf_key == 'tmin': 817 val = float(confs['tmin']) 818 self.set_parameter('tmin', val) 819 820 if conf_key == 'tmax': 821 val = float(confs['tmax']) 822 self.set_parameter('tmax', val) 823 824 if conf_key == 'tstep': 825 val = float(confs['tstep']) 826 self.set_parameter('tstep', val) 827 828 # Group velocity finite difference 829 if conf_key == 'gv_delta_q': 830 self.set_parameter('gv_delta_q', float(confs['gv_delta_q'])) 831 832 # Compression option for writing int hdf5 833 if conf_key == 'hdf5_compression': 834 hdf5_compression = confs['hdf5_compression'] 835 try: 836 compression = int(hdf5_compression) 837 except ValueError: # str 838 compression = hdf5_compression 839 if compression.lower() == "none": 840 compression = None 841 except TypeError: # None (this will not happen) 842 compression = hdf5_compression 843 self.set_parameter('hdf5_compression', compression) 844 845 def set_parameter(self, key, val): 846 self._parameters[key] = val 847 848 def set_settings(self): 849 params = self._parameters 850 851 # Chemical symbols 852 if 'atom_name' in params: 853 self._settings.set_chemical_symbols(params['atom_name']) 854 855 # Sets of band indices that are summed 856 if 'band_indices' in params: 857 self._settings.set_band_indices(params['band_indices']) 858 859 # Filename of input unit cell 860 if 'cell_filename' in params: 861 self._settings.set_cell_filename(params['cell_filename']) 862 863 # Is getting least displacements? 864 if 'create_displacements' in params: 865 self._settings.set_create_displacements( 866 params['create_displacements']) 867 868 # Cutoff frequency 869 if 'cutoff_frequency' in params: 870 self._settings.set_cutoff_frequency(params['cutoff_frequency']) 871 872 # Diagonal displacement 873 if 'diag' in params: 874 self._settings.set_is_diagonal_displacement(params['diag']) 875 876 # Distance of finite displacements introduced 877 if 'displacement_distance' in params: 878 self._settings.set_displacement_distance( 879 params['displacement_distance']) 880 881 # Decimals of values of dynamical matrxi 882 if 'dm_decimals' in params: 883 self._settings.set_dm_decimals(int(params['dm_decimals'])) 884 885 # Force calculator 886 if 'calculator' in params: 887 self._settings.set_calculator(params['calculator']) 888 889 # Force constants calculator 890 if 'fc_calculator' in params: 891 self._settings.set_fc_calculator(params['fc_calculator']) 892 893 # Force constants calculator options as str 894 if 'fc_calculator_options' in params: 895 self._settings.set_fc_calculator_options( 896 params['fc_calculator_options']) 897 898 # Decimals of values of force constants 899 if 'fc_decimals' in params: 900 self._settings.set_fc_decimals(int(params['fc_decimals'])) 901 902 # Enforce translational invariance and index permutation symmetry 903 # to force constants? 904 if 'fc_symmetry' in params: 905 self._settings.set_fc_symmetry(params['fc_symmetry']) 906 907 # Frequency unit conversion factor 908 if 'frequency_conversion_factor' in params: 909 self._settings.set_frequency_conversion_factor( 910 params['frequency_conversion_factor']) 911 912 # This scale factor is multiplied to force constants by 913 # fc * scale_factor ** 2, therefore only changes 914 # frequencies but does not change NAC part. 915 if 'frequency_scale_factor' in params: 916 self._settings.set_frequency_scale_factor( 917 params['frequency_scale_factor']) 918 919 # Spectram drawing step 920 if 'fpitch' in params: 921 self._settings.set_frequency_pitch(params['fpitch']) 922 923 # Number of sampling points for spectram drawing 924 if 'num_frequency_points' in params: 925 self._settings.set_num_frequency_points( 926 params['num_frequency_points']) 927 928 # Group velocity finite difference 929 if 'gv_delta_q' in params: 930 self._settings.set_group_velocity_delta_q(params['gv_delta_q']) 931 932 # Mesh sampling numbers 933 if 'mesh_numbers' in params: 934 self._settings.set_mesh_numbers(params['mesh_numbers']) 935 936 # Is getting eigenvectors? 937 if 'is_eigenvectors' in params: 938 self._settings.set_is_eigenvectors(params['is_eigenvectors']) 939 940 # Is reciprocal mesh symmetry searched? 941 if 'is_mesh_symmetry' in params: 942 self._settings.set_is_mesh_symmetry(params['is_mesh_symmetry']) 943 944 # Non analytical term correction? 945 if 'is_nac' in params: 946 self._settings.set_is_nac(params['is_nac']) 947 948 # Is crystal symmetry searched? 949 if 'is_symmetry' in params: 950 self._settings.set_is_symmetry(params['is_symmetry']) 951 952 # Tetrahedron method 953 if 'is_tetrahedron_method' in params: 954 self._settings.set_is_tetrahedron_method( 955 params['is_tetrahedron_method']) 956 957 # Trigonal displacement 958 if 'is_trigonal_displacement' in params: 959 self._settings.set_is_trigonal_displacement( 960 params['is_trigonal_displacement']) 961 962 # Magnetic moments 963 if 'magmom' in params: 964 self._settings.set_magnetic_moments(params['magmom']) 965 966 # Atomic mass 967 if 'mass' in params: 968 self._settings.set_masses(params['mass']) 969 970 # Plus minus displacement 971 if 'pm_displacement' in params: 972 self._settings.set_is_plusminus_displacement( 973 params['pm_displacement']) 974 975 # Primitive cell shape 976 if 'primitive_axes' in params: 977 self._settings.set_primitive_matrix(params['primitive_axes']) 978 979 # Q-points mode 980 if 'qpoints' in params: 981 self._settings.set_qpoints(params['qpoints']) 982 983 if 'read_qpoints' in params: 984 if params['read_qpoints']: 985 self._settings.set_read_qpoints(params['read_qpoints']) 986 987 # non analytical term correction method 988 if 'nac_method' in params: 989 self._settings.set_nac_method(params['nac_method']) 990 991 # q-direction for non analytical term correction 992 if 'nac_q_direction' in params: 993 self._settings.set_nac_q_direction(params['nac_q_direction']) 994 995 # Smearing width 996 if 'sigma' in params: 997 self._settings.set_sigma(params['sigma']) 998 999 # Symmetry tolerance 1000 if 'symmetry_tolerance' in params: 1001 self._settings.set_symmetry_tolerance(params['symmetry_tolerance']) 1002 1003 # Supercell size 1004 if 'supercell_matrix' in params: 1005 self._settings.set_supercell_matrix(params['supercell_matrix']) 1006 1007 # Temperatures or temerature range 1008 if 'temperatures' in params: 1009 self._settings.set_temperatures(params['temperatures']) 1010 if 'tmax' in params: 1011 self._settings.set_max_temperature(params['tmax']) 1012 if 'tmin' in params: 1013 self._settings.set_min_temperature(params['tmin']) 1014 if 'tstep' in params: 1015 self._settings.set_temperature_step(params['tstep']) 1016 1017 # Band paths 1018 if 'band_paths' in params: 1019 self._settings.set_band_paths(params['band_paths']) 1020 1021 # This number includes end points 1022 if 'band_points' in params: 1023 self._settings.set_band_points(params['band_points']) 1024 1025 if 'is_band_const_interval' in params: 1026 self._settings.set_is_band_const_interval( 1027 params['is_band_const_interval']) 1028 1029 # Compression option for writing int hdf5 1030 if 'hdf5_compression' in params: 1031 self._settings.set_hdf5_compression(params['hdf5_compression']) 1032 1033 1034# 1035# For phonopy 1036# 1037class PhonopySettings(Settings): 1038 """Phonopy settings container 1039 1040 Basic part is stored in Settings and extended part is stored in this class. 1041 1042 This works almost like a dictionary. 1043 Method names without 'set_' and 'get_' and keys of self._v have to be same. 1044 1045 """ 1046 1047 _default = { 1048 'anime_band_index': None, 1049 'anime_amplitude': None, 1050 'anime_division': None, 1051 'anime_qpoint': None, 1052 'anime_shift': None, 1053 'anime_type': 'v_sim', 1054 'band_format': 'yaml', 1055 'band_labels': None, 1056 'create_force_sets': None, 1057 'create_force_sets_zero': None, 1058 'create_force_constants': None, 1059 'cutoff_radius': None, 1060 'dos': None, 1061 'fc_spg_symmetry': False, 1062 'fits_Debye_model': False, 1063 'max_frequency': None, 1064 'min_frequency': None, 1065 'irreps_q_point': None, 1066 'irreps_tolerance': 1e-5, 1067 'is_band_connection': False, 1068 'is_dos_mode': False, 1069 'is_full_fc': False, 1070 'is_group_velocity': False, 1071 'is_gamma_center': False, 1072 'is_hdf5': False, 1073 'is_legacy_plot': False, 1074 'is_little_cogroup': False, 1075 'is_moment': False, 1076 'is_plusminus_displacement': 'auto', 1077 'is_thermal_displacements': False, 1078 'is_thermal_displacement_matrices': False, 1079 'is_thermal_distances': False, 1080 'is_thermal_properties': False, 1081 'is_projected_thermal_properties': False, 1082 'include_force_constants': False, 1083 'include_force_sets': False, 1084 'include_nac_params': False, 1085 'include_displacements': False, 1086 'lapack_solver': False, 1087 'mesh_shift': None, 1088 'mesh_format': 'yaml', 1089 'modulation': None, 1090 'moment_order': None, 1091 'random_displacements': None, 1092 'pdos_indices': None, 1093 'pretend_real': False, 1094 'projection_direction': None, 1095 'random_seed': None, 1096 'qpoints_format': 'yaml', 1097 'read_force_constants': False, 1098 'readfc_format': 'text', 1099 'run_mode': None, 1100 'save_params': False, 1101 'show_irreps': False, 1102 'store_dense_svecs': False, 1103 'thermal_atom_pairs': None, 1104 'thermal_displacement_matrix_temperatue': None, 1105 'write_dynamical_matrices': False, 1106 'write_mesh': True, 1107 'write_force_constants': False, 1108 'writefc_format': 'text', 1109 'xyz_projection': False 1110 } 1111 1112 def __init__(self, default=None): 1113 Settings.__init__(self) 1114 self.default.update(PhonopySettings._default.copy()) 1115 if default is not None: 1116 self.default.update(default) 1117 self._v = self.default.copy() 1118 1119 def set_anime_band_index(self, val): 1120 self._v['anime_band_index'] = val 1121 1122 def set_anime_amplitude(self, val): 1123 self._v['anime_amplitude'] = val 1124 1125 def set_anime_division(self, val): 1126 self._v['anime_division'] = val 1127 1128 def set_anime_qpoint(self, val): 1129 self._v['anime_qpoint'] = val 1130 1131 def set_anime_shift(self, val): 1132 self._v['anime_shift'] = val 1133 1134 def set_anime_type(self, val): 1135 self._v['anime_type'] = val 1136 1137 def set_band_format(self, val): 1138 self._v['band_format'] = val 1139 1140 def set_band_labels(self, val): 1141 self._v['band_labels'] = val 1142 1143 def set_create_force_sets(self, val): 1144 self._v['create_force_sets'] = val 1145 1146 def set_create_force_sets_zero(self, val): 1147 self._v['create_force_sets_zero'] = val 1148 1149 def set_create_force_constants(self, val): 1150 self._v['create_force_constants'] = val 1151 1152 def set_cutoff_radius(self, val): 1153 self._v['cutoff_radius'] = val 1154 1155 def set_fc_spg_symmetry(self, val): 1156 self._v['fc_spg_symmetry'] = val 1157 1158 def set_fits_Debye_model(self, val): 1159 self._v['fits_Debye_model'] = val 1160 1161 def set_max_frequency(self, val): 1162 self._v['max_frequency'] = val 1163 1164 def set_mesh_shift(self, val): 1165 self._v['mesh_shift'] = val 1166 1167 def set_min_frequency(self, val): 1168 self._v['min_frequency'] = val 1169 1170 def set_irreps_q_point(self, val): 1171 self._v['irreps_q_point'] = val 1172 1173 def set_irreps_tolerance(self, val): 1174 self._v['irreps_tolerance'] = val 1175 1176 def set_is_band_connection(self, val): 1177 self._v['is_band_connection'] = val 1178 1179 def set_is_dos_mode(self, val): 1180 self._v['is_dos_mode'] = val 1181 1182 def set_is_full_fc(self, val): 1183 self._v['is_full_fc'] = val 1184 1185 def set_is_gamma_center(self, val): 1186 self._v['is_gamma_center'] = val 1187 1188 def set_is_group_velocity(self, val): 1189 self._v['is_group_velocity'] = val 1190 1191 def set_is_hdf5(self, val): 1192 self._v['is_hdf5'] = val 1193 1194 def set_is_legacy_plot(self, val): 1195 self._v['is_legacy_plot'] = val 1196 1197 def set_is_little_cogroup(self, val): 1198 self._v['is_little_cogroup'] = val 1199 1200 def set_is_moment(self, val): 1201 self._v['is_moment'] = val 1202 1203 def set_is_projected_thermal_properties(self, val): 1204 self._v['is_projected_thermal_properties'] = val 1205 1206 def set_is_thermal_displacements(self, val): 1207 self._v['is_thermal_displacements'] = val 1208 1209 def set_is_thermal_displacement_matrices(self, val): 1210 self._v['is_thermal_displacement_matrices'] = val 1211 1212 def set_is_thermal_distances(self, val): 1213 self._v['is_thermal_distances'] = val 1214 1215 def set_is_thermal_properties(self, val): 1216 self._v['is_thermal_properties'] = val 1217 1218 def set_include_force_constants(self, val): 1219 self._v['include_force_constants'] = val 1220 1221 def set_include_force_sets(self, val): 1222 self._v['include_force_sets'] = val 1223 1224 def set_include_nac_params(self, val): 1225 self._v['include_nac_params'] = val 1226 1227 def set_include_displacements(self, val): 1228 self._v['include_displacements'] = val 1229 1230 def set_lapack_solver(self, val): 1231 self._v['lapack_solver'] = val 1232 1233 def set_mesh_format(self, val): 1234 self._v['mesh_format'] = val 1235 1236 def set_modulation(self, val): 1237 self._v['modulation'] = val 1238 1239 def set_moment_order(self, val): 1240 self._v['moment_order'] = val 1241 1242 def set_random_displacements(self, val): 1243 self._v['random_displacements'] = val 1244 1245 def set_pdos_indices(self, val): 1246 self._v['pdos_indices'] = val 1247 1248 def set_pretend_real(self, val): 1249 self._v['pretend_real'] = val 1250 1251 def set_projection_direction(self, val): 1252 self._v['projection_direction'] = val 1253 1254 def set_qpoints_format(self, val): 1255 self._v['qpoints_format'] = val 1256 1257 def set_random_seed(self, val): 1258 self._v['random_seed'] = val 1259 1260 def set_read_force_constants(self, val): 1261 self._v['read_force_constants'] = val 1262 1263 def set_readfc_format(self, val): 1264 self._v['readfc_format'] = val 1265 1266 def set_run_mode(self, val): 1267 self._v['run_mode'] = val 1268 1269 def set_thermal_atom_pairs(self, val): 1270 self._v['thermal_atom_pairs'] = val 1271 1272 def set_thermal_displacement_matrix_temperatue(self, val): 1273 self._v['thermal_displacement_matrix_temperatue'] = val 1274 1275 def set_save_params(self, val): 1276 self._v['save_params'] = val 1277 1278 def set_show_irreps(self, val): 1279 self._v['show_irreps'] = val 1280 1281 def set_store_dense_svecs(self, val): 1282 self._v['store_dense_svecs'] = val 1283 1284 def set_write_dynamical_matrices(self, val): 1285 self._v['write_dynamical_matrices'] = val 1286 1287 def set_write_force_constants(self, val): 1288 self._v['write_force_constants'] = val 1289 1290 def set_write_mesh(self, val): 1291 self._v['write_mesh'] = val 1292 1293 def set_writefc_format(self, val): 1294 self._v['writefc_format'] = val 1295 1296 def set_xyz_projection(self, val): 1297 self._v['xyz_projection'] = val 1298 1299 1300class PhonopyConfParser(ConfParser): 1301 """Phonopy conf parser.""" 1302 1303 def __init__(self, filename=None, args=None, default_settings=None): 1304 """Init method. 1305 1306 Note 1307 ---- 1308 This implementation is fragile. 1309 Remember that options have to be activated only 1310 when it changes the default value, i.e., 1311 _read_options has to be written in this way. 1312 1313 """ 1314 self._settings = PhonopySettings(default=default_settings) 1315 confs = {} 1316 if filename is not None: 1317 ConfParser.__init__(self, filename=filename) 1318 self.read_file() # store .conf file setting in self._confs 1319 self._parse_conf() # self.parameters[key] = val 1320 self._set_settings() # self.parameters -> PhonopySettings 1321 confs.update(self._confs) 1322 if args is not None: 1323 # To invoke ConfParser.__init__() to flush variables. 1324 ConfParser.__init__(self, args=args) 1325 self._read_options() # store options in self._confs 1326 self._parse_conf() # self.parameters[key] = val 1327 self._set_settings() # self.parameters -> PhonopySettings 1328 confs.update(self._confs) 1329 self._confs = confs 1330 1331 def _read_options(self): 1332 ConfParser.read_options(self) # store data in self._confs 1333 arg_list = vars(self._args) 1334 if 'band_format' in arg_list: 1335 if self._args.band_format: 1336 self._confs['band_format'] = self._args.band_format 1337 1338 if 'band_labels' in arg_list: 1339 if self._args.band_labels is not None: 1340 self._confs['band_labels'] = " ".join(self._args.band_labels) 1341 1342 if 'is_gamma_center' in arg_list: 1343 if self._args.is_gamma_center: 1344 self._confs['gamma_center'] = '.true.' 1345 1346 if 'create_force_sets' in arg_list: 1347 if self._args.create_force_sets: 1348 self._confs['create_force_sets'] = self._args.create_force_sets 1349 1350 if 'create_force_sets_zero' in arg_list: 1351 if self._args.create_force_sets_zero: 1352 fc_sets_zero = self._args.create_force_sets_zero 1353 self._confs['create_force_sets_zero'] = fc_sets_zero 1354 1355 if 'create_force_constants' in arg_list: 1356 if self._args.create_force_constants is not None: 1357 fc_filename = self._args.create_force_constants 1358 self._confs['create_force_constants'] = fc_filename 1359 1360 if 'is_dos_mode' in arg_list: 1361 if self._args.is_dos_mode: 1362 self._confs['dos'] = '.true.' 1363 1364 if 'pdos' in arg_list: 1365 if self._args.pdos is not None: 1366 self._confs['pdos'] = " ".join(self._args.pdos) 1367 1368 if 'xyz_projection' in arg_list: 1369 if self._args.xyz_projection: 1370 self._confs['xyz_projection'] = '.true.' 1371 1372 if 'fc_spg_symmetry' in arg_list: 1373 if self._args.fc_spg_symmetry: 1374 self._confs['fc_spg_symmetry'] = '.true.' 1375 1376 if 'is_full_fc' in arg_list: 1377 if self._args.is_full_fc: 1378 self._confs['full_force_constants'] = '.true.' 1379 1380 if 'fits_debye_model' in arg_list: 1381 if self._args.fits_debye_model: 1382 self._confs['debye_model'] = '.true.' 1383 1384 if 'fmax' in arg_list: 1385 if self._args.fmax: 1386 self._confs['fmax'] = self._args.fmax 1387 1388 if 'fmin' in arg_list: 1389 if self._args.fmin: 1390 self._confs['fmin'] = self._args.fmin 1391 1392 if 'is_thermal_properties' in arg_list: 1393 if self._args.is_thermal_properties: 1394 self._confs['tprop'] = '.true.' 1395 1396 if 'pretend_real' in arg_list: 1397 if self._args.pretend_real: 1398 self._confs['pretend_real'] = '.true.' 1399 1400 if 'is_projected_thermal_properties' in arg_list: 1401 if self._args.is_projected_thermal_properties: 1402 self._confs['ptprop'] = '.true.' 1403 1404 if 'is_thermal_displacements' in arg_list: 1405 if self._args.is_thermal_displacements: 1406 self._confs['tdisp'] = '.true.' 1407 1408 if 'is_thermal_displacement_matrices' in arg_list: 1409 if self._args.is_thermal_displacement_matrices: 1410 self._confs['tdispmat'] = '.true.' 1411 1412 if 'thermal_displacement_matrices_cif' in arg_list: 1413 opt_tdm_cif = self._args.thermal_displacement_matrices_cif 1414 if opt_tdm_cif: 1415 self._confs['tdispmat_cif'] = opt_tdm_cif 1416 1417 if 'projection_direction' in arg_list: 1418 opt_proj_dir = self._args.projection_direction 1419 if opt_proj_dir is not None: 1420 self._confs['projection_direction'] = " ".join(opt_proj_dir) 1421 1422 if 'read_force_constants' in arg_list: 1423 if self._args.read_force_constants: 1424 self._confs['read_force_constants'] = '.true.' 1425 1426 if 'write_force_constants' in arg_list: 1427 if self._args.write_force_constants: 1428 self._confs['write_force_constants'] = '.true.' 1429 1430 if 'readfc_format' in arg_list: 1431 if self._args.readfc_format: 1432 self._confs['readfc_format'] = self._args.readfc_format 1433 1434 if 'writefc_format' in arg_list: 1435 if self._args.writefc_format: 1436 self._confs['writefc_format'] = self._args.writefc_format 1437 1438 if 'fc_format' in arg_list: 1439 if self._args.fc_format: 1440 self._confs['fc_format'] = self._args.fc_format 1441 1442 if 'is_hdf5' in arg_list: 1443 if self._args.is_hdf5: 1444 self._confs['hdf5'] = '.true.' 1445 1446 if 'write_dynamical_matrices' in arg_list: 1447 if self._args.write_dynamical_matrices: 1448 self._confs['writedm'] = '.true.' 1449 1450 if 'write_mesh' in arg_list: 1451 if self._args.write_mesh is False: 1452 self._confs['write_mesh'] = '.false.' 1453 1454 if 'mesh_format' in arg_list: 1455 if self._args.mesh_format: 1456 self._confs['mesh_format'] = self._args.mesh_format 1457 1458 if 'qpoints_format' in arg_list: 1459 if self._args.qpoints_format: 1460 self._confs['qpoints_format'] = self._args.qpoints_format 1461 1462 if 'irreps_qpoint' in arg_list: 1463 if self._args.irreps_qpoint is not None: 1464 self._confs['irreps'] = " ".join(self._args.irreps_qpoint) 1465 1466 if 'save_params' in arg_list: 1467 if self._args.save_params: 1468 self._confs['save_params'] = '.true.' 1469 1470 if 'show_irreps' in arg_list: 1471 if self._args.show_irreps: 1472 self._confs['show_irreps'] = '.true.' 1473 1474 if 'is_little_cogroup' in arg_list: 1475 if self._args.is_little_cogroup: 1476 self._confs['little_cogroup'] = '.true.' 1477 1478 if 'is_legacy_plot' in arg_list: 1479 if self._args.is_legacy_plot: 1480 self._confs['legacy_plot'] = '.true.' 1481 1482 if 'is_band_connection' in arg_list: 1483 if self._args.is_band_connection: 1484 self._confs['band_connection'] = '.true.' 1485 1486 if 'cutoff_radius' in arg_list: 1487 if self._args.cutoff_radius: 1488 self._confs['cutoff_radius'] = self._args.cutoff_radius 1489 1490 if 'modulation' in arg_list: 1491 if self._args.modulation: 1492 self._confs['modulation'] = " ".join(self._args.modulation) 1493 1494 if 'anime' in arg_list: 1495 if self._args.anime: 1496 self._confs['anime'] = " ".join(self._args.anime) 1497 1498 if 'is_group_velocity' in arg_list: 1499 if self._args.is_group_velocity: 1500 self._confs['group_velocity'] = '.true.' 1501 1502 if 'is_moment' in arg_list: 1503 if self._args.is_moment: 1504 self._confs['moment'] = '.true.' 1505 1506 if 'moment_order' in arg_list: 1507 if self._args.moment_order: 1508 self._confs['moment_order'] = self._args.moment_order 1509 1510 if 'random_displacements' in arg_list: 1511 nrand = self._args.random_displacements 1512 if nrand: 1513 self._confs['random_displacements'] = nrand 1514 1515 if 'random_seed' in arg_list: 1516 if self._args.random_seed: 1517 seed = self._args.random_seed 1518 if (np.issubdtype(type(seed), np.integer) and 1519 seed >= 0 and seed < 2 ** 32): 1520 self._confs['random_seed'] = seed 1521 1522 if 'include_fc' in arg_list: 1523 if self._args.include_fc: 1524 self._confs['include_fc'] = '.true.' 1525 1526 if 'include_fs' in arg_list: 1527 if self._args.include_fs: 1528 self._confs['include_fs'] = '.true.' 1529 1530 if 'include_nac_params' in arg_list: 1531 if self._settings.default['include_nac_params']: 1532 if self._args.include_nac_params is False: 1533 self._confs['include_nac_params'] = '.false.' 1534 else: 1535 if self._args.include_nac_params: 1536 self._confs['include_nac_params'] = '.true.' 1537 1538 if 'include_disp' in arg_list: 1539 if self._args.include_disp: 1540 self._confs['include_disp'] = '.true.' 1541 1542 if 'include_all' in arg_list: 1543 if self._args.include_all: 1544 self._confs['include_all'] = '.true.' 1545 1546 if 'store_dense_svecs' in arg_list: 1547 if self._args.store_dense_svecs: 1548 self._confs['store_dense_svecs'] = '.true.' 1549 1550 if 'lapack_solver' in arg_list: 1551 if self._args.lapack_solver: 1552 self._confs['lapack_solver'] = '.true.' 1553 1554 # Overwrite 1555 if 'is_check_symmetry' in arg_list: 1556 if self._args.is_check_symmetry: 1557 # Dummy 'dim' setting for sym-check 1558 self._confs['dim'] = '1 1 1' 1559 1560 def _parse_conf(self): 1561 ConfParser.parse_conf(self) 1562 confs = self._confs 1563 1564 for conf_key in confs.keys(): 1565 if conf_key == 'band_format': 1566 self.set_parameter('band_format', confs['band_format'].lower()) 1567 1568 if conf_key == 'band_labels': 1569 labels = confs['band_labels'].split() 1570 self.set_parameter('band_labels', labels) 1571 1572 if conf_key == 'band_connection': 1573 if confs['band_connection'].lower() == '.true.': 1574 self.set_parameter('band_connection', True) 1575 elif confs['band_connection'].lower() == '.false.': 1576 self.set_parameter('band_connection', False) 1577 1578 if conf_key == 'legacy_plot': 1579 if confs['legacy_plot'].lower() == '.true.': 1580 self.set_parameter('legacy_plot', True) 1581 elif confs['legacy_plot'].lower() == '.false.': 1582 self.set_parameter('legacy_plot', False) 1583 1584 if conf_key == 'create_force_sets': 1585 if type(confs['create_force_sets']) is str: 1586 fnames = confs['create_force_sets'].split() 1587 else: 1588 fnames = confs['create_force_sets'] 1589 self.set_parameter('create_force_sets', fnames) 1590 1591 if conf_key == 'create_force_sets_zero': 1592 if type(confs['create_force_sets_zero']) is str: 1593 fnames = confs['create_force_sets_zero'].split() 1594 else: 1595 fnames = confs['create_force_sets_zero'] 1596 1597 self.set_parameter('create_force_sets_zero', fnames) 1598 1599 if conf_key == 'create_force_constants': 1600 self.set_parameter('create_force_constants', 1601 confs['create_force_constants']) 1602 1603 if conf_key == 'force_constants': 1604 self.set_parameter('force_constants', 1605 confs['force_constants'].lower()) 1606 1607 if conf_key == 'read_force_constants': 1608 if confs['read_force_constants'].lower() == '.true.': 1609 self.set_parameter('read_force_constants', True) 1610 elif confs['read_force_constants'].lower() == '.false.': 1611 self.set_parameter('read_force_constants', False) 1612 1613 if conf_key == 'write_force_constants': 1614 if confs['write_force_constants'].lower() == '.true.': 1615 self.set_parameter('write_force_constants', True) 1616 elif confs['write_force_constants'].lower() == '.false.': 1617 self.set_parameter('write_force_constants', False) 1618 1619 if conf_key == 'full_force_constants': 1620 if confs['full_force_constants'].lower() == '.true.': 1621 self.set_parameter('is_full_fc', True) 1622 elif confs['full_force_constants'].lower() == '.false.': 1623 self.set_parameter('is_full_fc', False) 1624 1625 if conf_key == 'cutoff_radius': 1626 val = float(confs['cutoff_radius']) 1627 self.set_parameter('cutoff_radius', val) 1628 1629 if conf_key == 'writedm': 1630 if confs['writedm'].lower() == '.true.': 1631 self.set_parameter('write_dynamical_matrices', True) 1632 elif confs['writedm'].lower() == '.false.': 1633 self.set_parameter('write_dynamical_matrices', False) 1634 1635 if conf_key == 'write_mesh': 1636 if confs['write_mesh'].lower() == '.true.': 1637 self.set_parameter('write_mesh', True) 1638 elif confs['write_mesh'].lower() == '.false.': 1639 self.set_parameter('write_mesh', False) 1640 1641 if conf_key == 'hdf5': 1642 if confs['hdf5'].lower() == '.true.': 1643 self.set_parameter('hdf5', True) 1644 elif confs['hdf5'].lower() == '.false.': 1645 self.set_parameter('hdf5', False) 1646 1647 if conf_key == 'mp_shift': 1648 vals = [fracval(x) for x in confs['mp_shift'].split()] 1649 if len(vals) < 3: 1650 self.setting_error("MP_SHIFT is incorrectly set.") 1651 self.set_parameter('mp_shift', vals[:3]) 1652 1653 if conf_key == 'mesh_format': 1654 self.set_parameter('mesh_format', confs['mesh_format'].lower()) 1655 1656 if conf_key == 'qpoints_format': 1657 self.set_parameter('qpoints_format', 1658 confs['qpoints_format'].lower()) 1659 1660 if conf_key == 'time_reversal_symmetry': 1661 if confs['time_reversal_symmetry'].lower() == '.true.': 1662 self.set_parameter('is_time_reversal_symmetry', True) 1663 elif confs['time_reversal_symmetry'].lower() == '.false.': 1664 self.set_parameter('is_time_reversal_symmetry', False) 1665 1666 if conf_key == 'gamma_center': 1667 if confs['gamma_center'].lower() == '.true.': 1668 self.set_parameter('is_gamma_center', True) 1669 elif confs['gamma_center'].lower() == '.false.': 1670 self.set_parameter('is_gamma_center', False) 1671 1672 if conf_key == 'fc_spg_symmetry': 1673 if confs['fc_spg_symmetry'].lower() == '.true.': 1674 self.set_parameter('fc_spg_symmetry', True) 1675 elif confs['fc_spg_symmetry'].lower() == '.false.': 1676 self.set_parameter('fc_spg_symmetry', False) 1677 1678 if conf_key == 'readfc_format': 1679 self.set_parameter('readfc_format', 1680 confs['readfc_format'].lower()) 1681 1682 if conf_key == 'writefc_format': 1683 self.set_parameter('writefc_format', 1684 confs['writefc_format'].lower()) 1685 1686 if conf_key == 'fc_format': 1687 self.set_parameter('readfc_format', confs['fc_format'].lower()) 1688 self.set_parameter('writefc_format', 1689 confs['fc_format'].lower()) 1690 1691 # Animation 1692 if conf_key == 'anime': 1693 vals = [] 1694 data = confs['anime'].split() 1695 if len(data) < 3: 1696 self.setting_error("ANIME is incorrectly set.") 1697 else: 1698 self.set_parameter('anime', data) 1699 1700 if conf_key == 'anime_type': 1701 anime_type = confs['anime_type'].lower() 1702 if anime_type in ('arc', 'v_sim', 'poscar', 'xyz', 'jmol'): 1703 self.set_parameter('anime_type', anime_type) 1704 else: 1705 self.setting_error("%s is not available for ANIME_TYPE tag." 1706 % confs['anime_type']) 1707 1708 # Modulation 1709 if conf_key == 'modulation': 1710 self._parse_conf_modulation(confs['modulation']) 1711 1712 # Character table 1713 if conf_key == 'irreps': 1714 vals = [fracval(x) for x in confs['irreps'].split()] 1715 if len(vals) == 3 or len(vals) == 4: 1716 self.set_parameter('irreps_qpoint', vals) 1717 else: 1718 self.setting_error("IRREPS is incorrectly set.") 1719 1720 if conf_key == 'show_irreps': 1721 if confs['show_irreps'].lower() == '.true.': 1722 self.set_parameter('show_irreps', True) 1723 elif confs['show_irreps'].lower() == '.false.': 1724 self.set_parameter('show_irreps', False) 1725 1726 if conf_key == 'little_cogroup': 1727 if confs['little_cogroup'].lower() == '.true.': 1728 self.set_parameter('little_cogroup', True) 1729 elif confs['little_cogroup'].lower() == '.false.': 1730 self.set_parameter('little_cogroup', False) 1731 1732 # DOS 1733 if conf_key == 'pdos': 1734 if confs['pdos'].strip().lower() == 'auto': 1735 self.set_parameter('pdos', 'auto') 1736 else: 1737 vals = [] 1738 for index_set in confs['pdos'].split(','): 1739 vals.append([int(x) - 1 for x in index_set.split()]) 1740 self.set_parameter('pdos', vals) 1741 1742 if conf_key == 'xyz_projection': 1743 if confs['xyz_projection'].lower() == '.true.': 1744 self.set_parameter('xyz_projection', True) 1745 elif confs['xyz_projection'].lower() == '.false.': 1746 self.set_parameter('xyz_projection', False) 1747 1748 if conf_key == 'dos': 1749 if confs['dos'].lower() == '.true.': 1750 self.set_parameter('dos', True) 1751 elif confs['dos'].lower() == '.false.': 1752 self.set_parameter('dos', False) 1753 1754 if conf_key == 'debye_model': 1755 if confs['debye_model'].lower() == '.true.': 1756 self.set_parameter('fits_debye_model', True) 1757 elif confs['debye_model'].lower() == '.false.': 1758 self.set_parameter('fits_debye_model', False) 1759 1760 if conf_key == 'dos_range': 1761 vals = [float(x) for x in confs['dos_range'].split()] 1762 self.set_parameter('dos_range', vals) 1763 1764 if conf_key == 'fmax': 1765 self.set_parameter('fmax', float(confs['fmax'])) 1766 1767 if conf_key == 'fmin': 1768 self.set_parameter('fmin', float(confs['fmin'])) 1769 1770 # Thermal properties 1771 if conf_key == 'tprop': 1772 if confs['tprop'].lower() == '.true.': 1773 self.set_parameter('tprop', True) 1774 if confs['tprop'].lower() == '.false.': 1775 self.set_parameter('tprop', False) 1776 1777 # Projected thermal properties 1778 if conf_key == 'ptprop': 1779 if confs['ptprop'].lower() == '.true.': 1780 self.set_parameter('ptprop', True) 1781 elif confs['ptprop'].lower() == '.false.': 1782 self.set_parameter('ptprop', False) 1783 1784 # Use imaginary frequency as real for thermal property calculation 1785 if conf_key == 'pretend_real': 1786 if confs['pretend_real'].lower() == '.true.': 1787 self.set_parameter('pretend_real', True) 1788 elif confs['pretend_real'].lower() == '.false.': 1789 self.set_parameter('pretend_real', False) 1790 1791 # Thermal displacement 1792 if conf_key == 'tdisp': 1793 if confs['tdisp'].lower() == '.true.': 1794 self.set_parameter('tdisp', True) 1795 elif confs['tdisp'].lower() == '.false.': 1796 self.set_parameter('tdisp', False) 1797 1798 # Thermal displacement matrices 1799 if conf_key == 'tdispmat': 1800 if confs['tdispmat'].lower() == '.true.': 1801 self.set_parameter('tdispmat', True) 1802 elif confs['tdispmat'].lower() == '.false.': 1803 self.set_parameter('tdispmat', False) 1804 1805 # Write thermal displacement matrices to cif file, 1806 # for which the temperature to execute is stored. 1807 if conf_key == 'tdispmat_cif': 1808 self.set_parameter('tdispmat_cif', float(confs['tdispmat_cif'])) 1809 1810 # Thermal distance 1811 if conf_key == 'tdistance': 1812 atom_pairs = [] 1813 for atoms in confs['tdistance'].split(','): 1814 pair = [int(x) - 1 for x in atoms.split()] 1815 if len(pair) == 2: 1816 atom_pairs.append(pair) 1817 else: 1818 self.setting_error( 1819 "TDISTANCE is incorrectly specified.") 1820 if len(atom_pairs) > 0: 1821 self.set_parameter('tdistance', atom_pairs) 1822 1823 # Projection direction used for thermal displacements and PDOS 1824 if conf_key == 'projection_direction': 1825 vals = [float(x) for x in confs['projection_direction'].split()] 1826 if len(vals) < 3: 1827 self.setting_error( 1828 "PROJECTION_DIRECTION (--pd) is incorrectly specified.") 1829 else: 1830 self.set_parameter('projection_direction', vals) 1831 1832 # Group velocity 1833 if conf_key == 'group_velocity': 1834 if confs['group_velocity'].lower() == '.true.': 1835 self.set_parameter('is_group_velocity', True) 1836 elif confs['group_velocity'].lower() == '.false.': 1837 self.set_parameter('is_group_velocity', False) 1838 1839 # Moment of phonon states distribution 1840 if conf_key == 'moment': 1841 if confs['moment'].lower() == '.true.': 1842 self.set_parameter('moment', True) 1843 elif confs['moment'].lower() == '.false.': 1844 self.set_parameter('moment', False) 1845 1846 if conf_key == 'moment_order': 1847 self.set_parameter('moment_order', int(confs['moment_order'])) 1848 1849 # Number of supercells with random displacements 1850 if conf_key == 'random_displacements': 1851 self.set_parameter('random_displacements', 1852 int(confs['random_displacements'])) 1853 1854 if conf_key == 'random_seed': 1855 self.set_parameter('random_seed', int(confs['random_seed'])) 1856 1857 # Use Lapack solver via Lapacke 1858 if conf_key == 'lapack_solver': 1859 if confs['lapack_solver'].lower() == '.true.': 1860 self.set_parameter('lapack_solver', True) 1861 elif confs['lapack_solver'].lower() == '.false.': 1862 self.set_parameter('lapack_solver', False) 1863 1864 # Select yaml summary contents 1865 if conf_key == 'save_params': 1866 if confs['save_params'].lower() == '.true.': 1867 self.set_parameter('save_params', True) 1868 elif confs['save_params'].lower() == '.false.': 1869 self.set_parameter('save_params', False) 1870 1871 if conf_key == 'include_fc': 1872 if confs['include_fc'].lower() == '.true.': 1873 self.set_parameter('include_fc', True) 1874 elif confs['include_fc'].lower() == '.false.': 1875 self.set_parameter('include_fc', False) 1876 1877 if conf_key == 'include_fs': 1878 if confs['include_fs'].lower() == '.true.': 1879 self.set_parameter('include_fs', True) 1880 elif confs['include_fs'].lower() == '.false.': 1881 self.set_parameter('include_fs', False) 1882 1883 if conf_key in ('include_born', 'include_nac_params'): 1884 if confs[conf_key].lower() == '.true.': 1885 self.set_parameter('include_nac_params', True) 1886 elif confs[conf_key].lower() == '.false.': 1887 self.set_parameter('include_nac_params', False) 1888 1889 if conf_key == 'include_disp': 1890 if confs['include_disp'].lower() == '.true.': 1891 self.set_parameter('include_disp', True) 1892 elif confs['include_disp'].lower() == '.false.': 1893 self.set_parameter('include_disp', False) 1894 1895 if conf_key == 'include_all': 1896 if confs['include_all'].lower() == '.true.': 1897 self.set_parameter('include_all', True) 1898 elif confs['include_all'].lower() == '.false.': 1899 self.set_parameter('include_all', False) 1900 1901 # Pair shortest vectors in supercell are stored in dense format. 1902 if conf_key == 'store_dense_svecs': 1903 if confs['store_dense_svecs'].lower() == '.true.': 1904 self.set_parameter('store_dense_svecs', True) 1905 1906 def _parse_conf_modulation(self, conf_modulation): 1907 modulation = {} 1908 modulation['dimension'] = [1, 1, 1] 1909 modulation['order'] = None 1910 mod_list = conf_modulation.split(',') 1911 header = mod_list[0].split() 1912 if len(header) > 2 and len(mod_list) > 1: 1913 if len(header) > 8: 1914 dimension = [int(x) for x in header[:9]] 1915 modulation['dimension'] = dimension 1916 if len(header) > 11: 1917 delta_q = [float(x) for x in header[9:12]] 1918 modulation['delta_q'] = delta_q 1919 if len(header) == 13: 1920 modulation['order'] = int(header[12]) 1921 else: 1922 dimension = [int(x) for x in header[:3]] 1923 modulation['dimension'] = dimension 1924 if len(header) > 3: 1925 delta_q = [float(x) for x in header[3:6]] 1926 modulation['delta_q'] = delta_q 1927 if len(header) == 7: 1928 modulation['order'] = int(header[6]) 1929 1930 vals = [] 1931 for phonon_mode in mod_list[1:]: 1932 mode_conf = [x for x in phonon_mode.split()] 1933 if len(mode_conf) < 4 or len(mode_conf) > 6: 1934 self.setting_error("MODULATION tag is wrongly set.") 1935 break 1936 else: 1937 q = [fracval(x) for x in mode_conf[:3]] 1938 1939 if len(mode_conf) == 4: 1940 vals.append([q, int(mode_conf[3]) - 1, 1.0, 0]) 1941 elif len(mode_conf) == 5: 1942 vals.append([q, 1943 int(mode_conf[3]) - 1, 1944 float(mode_conf[4]), 1945 0]) 1946 else: 1947 vals.append([q, 1948 int(mode_conf[3]) - 1, 1949 float(mode_conf[4]), 1950 float(mode_conf[5])]) 1951 1952 modulation['modulations'] = vals 1953 self.set_parameter('modulation', modulation) 1954 else: 1955 self.setting_error("MODULATION tag is wrongly set.") 1956 1957 def _set_settings(self): 1958 self.set_settings() 1959 params = self._parameters 1960 1961 # Create FORCE_SETS 1962 if 'create_force_sets' in params: 1963 self._settings.set_create_force_sets(params['create_force_sets']) 1964 1965 if 'create_force_sets_zero' in params: 1966 self._settings.set_create_force_sets_zero( 1967 params['create_force_sets_zero']) 1968 1969 if 'create_force_constants' in params: 1970 self._settings.set_create_force_constants( 1971 params['create_force_constants']) 1972 1973 # Is force constants written or read? 1974 if 'force_constants' in params: 1975 if params['force_constants'] == 'write': 1976 self._settings.set_write_force_constants(True) 1977 elif params['force_constants'] == 'read': 1978 self._settings.set_read_force_constants(True) 1979 1980 if 'read_force_constants' in params: 1981 self._settings.set_read_force_constants( 1982 params['read_force_constants']) 1983 1984 if 'write_force_constants' in params: 1985 self._settings.set_write_force_constants( 1986 params['write_force_constants']) 1987 1988 if 'is_full_fc' in params: 1989 self._settings.set_is_full_fc(params['is_full_fc']) 1990 1991 # Enforce space group symmetyr to force constants? 1992 if 'fc_spg_symmetry' in params: 1993 self._settings.set_fc_spg_symmetry(params['fc_spg_symmetry']) 1994 1995 if 'readfc_format' in params: 1996 self._settings.set_readfc_format(params['readfc_format']) 1997 1998 if 'writefc_format' in params: 1999 self._settings.set_writefc_format(params['writefc_format']) 2000 2001 # Use hdf5? 2002 if 'hdf5' in params: 2003 self._settings.set_is_hdf5(params['hdf5']) 2004 2005 # Cutoff radius of force constants 2006 if 'cutoff_radius' in params: 2007 self._settings.set_cutoff_radius(params['cutoff_radius']) 2008 2009 # Mesh 2010 if 'mesh_numbers' in params: 2011 self._settings.set_run_mode('mesh') 2012 self._settings.set_mesh_numbers(params['mesh_numbers']) 2013 if 'mp_shift' in params: 2014 self._settings.set_mesh_shift(params['mp_shift']) 2015 if 'is_time_reversal_symmetry' in params: 2016 self._settings.set_is_time_reversal_symmetry( 2017 params['is_time_reversal_symmetry']) 2018 if 'is_mesh_symmetry' in params: 2019 self._settings.set_is_mesh_symmetry(params['is_mesh_symmetry']) 2020 if 'is_gamma_center' in params: 2021 self._settings.set_is_gamma_center(params['is_gamma_center']) 2022 if 'mesh_format' in params: 2023 self._settings.set_mesh_format(params['mesh_format']) 2024 2025 # band mode 2026 if 'band_paths' in params: 2027 self._settings.set_run_mode('band') 2028 if 'band_format' in params: 2029 self._settings.set_band_format(params['band_format']) 2030 if 'band_labels' in params: 2031 self._settings.set_band_labels(params['band_labels']) 2032 if 'band_connection' in params: 2033 self._settings.set_is_band_connection(params['band_connection']) 2034 if 'legacy_plot' in params: 2035 self._settings.set_is_legacy_plot(params['legacy_plot']) 2036 2037 # Q-points mode 2038 if 'qpoints' in params or 'read_qpoints' in params: 2039 self._settings.set_run_mode('qpoints') 2040 if self._settings.run_mode == 'qpoints': 2041 if 'qpoints_format' in params: 2042 self._settings.set_qpoints_format(params['qpoints_format']) 2043 2044 # Whether write out dynamical matrices or not 2045 if 'write_dynamical_matrices' in params: 2046 self._settings.set_write_dynamical_matrices( 2047 params['write_dynamical_matrices']) 2048 2049 # Whether write out mesh.yaml or mesh.hdf5 2050 if 'write_mesh' in params: 2051 self._settings.set_write_mesh(params['write_mesh']) 2052 2053 # Anime mode 2054 if 'anime_type' in params: 2055 self._settings.set_anime_type(params['anime_type']) 2056 2057 if 'anime' in params: 2058 self._settings.set_run_mode('anime') 2059 anime_type = self._settings.anime_type 2060 if anime_type == 'v_sim': 2061 qpoints = [fracval(x) for x in params['anime'][0:3]] 2062 self._settings.set_anime_qpoint(qpoints) 2063 if len(params['anime']) > 3: 2064 self._settings.set_anime_amplitude(float(params['anime'][3])) 2065 else: 2066 self._settings.set_anime_band_index(int(params['anime'][0])) 2067 self._settings.set_anime_amplitude(float(params['anime'][1])) 2068 self._settings.set_anime_division(int(params['anime'][2])) 2069 if len(params['anime']) == 6: 2070 self._settings.set_anime_shift( 2071 [fracval(x) for x in params['anime'][3:6]]) 2072 2073 # Modulation mode 2074 if 'modulation' in params: 2075 self._settings.set_run_mode('modulation') 2076 self._settings.set_modulation(params['modulation']) 2077 2078 # Character table mode 2079 if 'irreps_qpoint' in params: 2080 self._settings.set_run_mode('irreps') 2081 self._settings.set_irreps_q_point( 2082 params['irreps_qpoint'][:3]) 2083 if len(params['irreps_qpoint']) == 4: 2084 self._settings.set_irreps_tolerance(params['irreps_qpoint'][3]) 2085 if 'show_irreps' in params: 2086 self._settings.set_show_irreps(params['show_irreps']) 2087 if 'little_cogroup' in params: 2088 self._settings.set_is_little_cogroup(params['little_cogroup']) 2089 2090 # DOS 2091 if 'dos_range' in params: 2092 fmin = params['dos_range'][0] 2093 fmax = params['dos_range'][1] 2094 fpitch = params['dos_range'][2] 2095 self._settings.set_min_frequency(fmin) 2096 self._settings.set_max_frequency(fmax) 2097 self._settings.set_frequency_pitch(fpitch) 2098 if 'dos' in params: 2099 self._settings.set_is_dos_mode(params['dos']) 2100 2101 if 'fits_debye_model' in params: 2102 self._settings.set_fits_Debye_model(params['fits_debye_model']) 2103 2104 if 'fmax' in params: 2105 self._settings.set_max_frequency(params['fmax']) 2106 2107 if 'fmin' in params: 2108 self._settings.set_min_frequency(params['fmin']) 2109 2110 # Project PDOS x, y, z directions in Cartesian coordinates 2111 if 'xyz_projection' in params: 2112 self._settings.set_xyz_projection(params['xyz_projection']) 2113 if ('pdos' not in params and 2114 self._settings.pdos_indices is None): 2115 self.set_parameter('pdos', []) 2116 2117 if 'pdos' in params: 2118 self._settings.set_pdos_indices(params['pdos']) 2119 self._settings.set_is_eigenvectors(True) 2120 self._settings.set_is_mesh_symmetry(False) 2121 2122 if ('projection_direction' in params and 2123 not self._settings.xyz_projection): 2124 self._settings.set_projection_direction( 2125 params['projection_direction']) 2126 self._settings.set_is_eigenvectors(True) 2127 self._settings.set_is_mesh_symmetry(False) 2128 2129 # Thermal properties 2130 if 'tprop' in params: 2131 self._settings.set_is_thermal_properties(params['tprop']) 2132 # Exclusive conditions 2133 self._settings.set_is_thermal_displacements(False) 2134 self._settings.set_is_thermal_displacement_matrices(False) 2135 self._settings.set_is_thermal_distances(False) 2136 2137 # Projected thermal properties 2138 if 'ptprop' in params and params['ptprop']: 2139 self._settings.set_is_thermal_properties(True) 2140 self._settings.set_is_projected_thermal_properties(True) 2141 self._settings.set_is_eigenvectors(True) 2142 self._settings.set_is_mesh_symmetry(False) 2143 # Exclusive conditions 2144 self._settings.set_is_thermal_displacements(False) 2145 self._settings.set_is_thermal_displacement_matrices(False) 2146 self._settings.set_is_thermal_distances(False) 2147 2148 # Use imaginary frequency as real for thermal property calculation 2149 if 'pretend_real' in params: 2150 self._settings.set_pretend_real(params['pretend_real']) 2151 2152 # Thermal displacements 2153 if 'tdisp' in params and params['tdisp']: 2154 self._settings.set_is_thermal_displacements(True) 2155 self._settings.set_is_eigenvectors(True) 2156 self._settings.set_is_mesh_symmetry(False) 2157 # Exclusive conditions 2158 self._settings.set_is_thermal_properties(False) 2159 self._settings.set_is_thermal_displacement_matrices(False) 2160 self._settings.set_is_thermal_distances(True) 2161 2162 # Thermal displacement matrices 2163 if ('tdispmat' in params and params['tdispmat'] or 2164 'tdispmat_cif' in params): 2165 self._settings.set_is_thermal_displacement_matrices(True) 2166 self._settings.set_is_eigenvectors(True) 2167 self._settings.set_is_mesh_symmetry(False) 2168 # Exclusive conditions 2169 self._settings.set_is_thermal_properties(False) 2170 self._settings.set_is_thermal_displacements(False) 2171 self._settings.set_is_thermal_distances(False) 2172 2173 # Temperature used to calculate thermal displacement matrix 2174 # to write aniso_U to cif 2175 if 'tdispmat_cif' in params: 2176 self._settings.set_thermal_displacement_matrix_temperature( 2177 params['tdispmat_cif']) 2178 2179 # Thermal distances 2180 if 'tdistance' in params: 2181 self._settings.set_is_thermal_distances(True) 2182 self._settings.set_is_eigenvectors(True) 2183 self._settings.set_is_mesh_symmetry(False) 2184 self._settings.set_thermal_atom_pairs(params['tdistance']) 2185 # Exclusive conditions 2186 self._settings.set_is_thermal_properties(False) 2187 self._settings.set_is_thermal_displacements(False) 2188 self._settings.set_is_thermal_displacement_matrices(False) 2189 2190 # Group velocity 2191 if 'is_group_velocity' in params: 2192 self._settings.set_is_group_velocity(params['is_group_velocity']) 2193 2194 # Moment mode 2195 if 'moment' in params: 2196 self._settings.set_is_moment(params['moment']) 2197 self._settings.set_is_eigenvectors(True) 2198 self._settings.set_is_mesh_symmetry(False) 2199 2200 if self._settings.is_moment: 2201 if 'moment_order' in params: 2202 self._settings.set_moment_order(params['moment_order']) 2203 2204 # Number of supercells with random displacements 2205 if 'random_displacements' in params: 2206 self._settings.set_random_displacements( 2207 params['random_displacements']) 2208 2209 if 'random_seed' in params: 2210 self._settings.set_random_seed(params['random_seed']) 2211 2212 # Use Lapack solver via Lapacke 2213 if 'lapack_solver' in params: 2214 self._settings.set_lapack_solver(params['lapack_solver']) 2215 2216 # Select yaml summary contents 2217 if 'save_params' in params: 2218 self._settings.set_save_params(params['save_params']) 2219 2220 if 'include_fc' in params: 2221 self._settings.set_include_force_constants(params['include_fc']) 2222 2223 if 'include_fs' in params: 2224 self._settings.set_include_force_sets(params['include_fs']) 2225 2226 if 'include_nac_params' in params: 2227 self._settings.set_include_nac_params(params['include_nac_params']) 2228 2229 if 'include_disp' in params: 2230 self._settings.set_include_displacements(params['include_disp']) 2231 2232 if 'include_all' in params: 2233 self._settings.set_include_force_constants(True) 2234 self._settings.set_include_force_sets(True) 2235 self._settings.set_include_nac_params(True) 2236 self._settings.set_include_displacements(True) 2237 2238 # Pair shortest vectors in supercell are stored in dense format. 2239 if 'store_dense_svecs' in params: 2240 self._settings.set_store_dense_svecs(params['store_dense_svecs']) 2241 2242 # *********************************************************** 2243 # This has to come last in this method to overwrite run_mode. 2244 # *********************************************************** 2245 if 'pdos' in params and params['pdos'] == 'auto': 2246 if 'band_paths' in params: 2247 self._settings.set_run_mode('band_mesh') 2248 else: 2249 self._settings.set_run_mode('mesh') 2250 2251 if 'mesh_numbers' in params and 'band_paths' in params: 2252 self._settings.set_run_mode('band_mesh') 2253