You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

nb14.py 7.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # Copyright 2021 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. '''NON BOND'''
  16. class NON_BOND_14:
  17. '''NON BOND'''
  18. def __init__(self, controller, dihedral, atom_numbers):
  19. self.dihedral_with_hydrogen = dihedral.dihedral_with_hydrogen
  20. self.dihedral_numbers = dihedral.dihedral_numbers
  21. self.dihedral_type_numbers = dihedral.dihedral_type_numbers
  22. self.atom_numbers = atom_numbers
  23. if controller.amber_parm is not None:
  24. file_path = controller.amber_parm
  25. self.read_information_from_amberfile(file_path)
  26. self.h_atom_a = self.h_atom_a[:self.nb14_numbers]
  27. self.h_atom_b = self.h_atom_b[:self.nb14_numbers]
  28. self.h_lj_scale_factor = self.h_lj_scale_factor[:self.nb14_numbers]
  29. self.h_cf_scale_factor = self.h_cf_scale_factor[:self.nb14_numbers]
  30. def read_information_from_amberfile(self, file_path):
  31. '''read amber file'''
  32. file = open(file_path, 'r')
  33. context = file.readlines()
  34. file.close()
  35. self.cf_scale_type = [0] * self.dihedral_type_numbers
  36. self.lj_scale_type = [0] * self.dihedral_type_numbers
  37. for idx, val in enumerate(context):
  38. if "%FLAG SCEE_SCALE_FACTOR" in val:
  39. count = 0
  40. start_idx = idx
  41. information = []
  42. while count < self.dihedral_type_numbers:
  43. start_idx += 1
  44. if "%FORMAT" in context[start_idx]:
  45. continue
  46. else:
  47. value = list(map(float, context[start_idx].strip().split()))
  48. information.extend(value)
  49. count += len(value)
  50. self.cf_scale_type = information[:self.dihedral_type_numbers]
  51. break
  52. for idx, val in enumerate(context):
  53. if "%FLAG SCNB_SCALE_FACTOR" in val:
  54. count = 0
  55. start_idx = idx
  56. information = []
  57. while count < self.dihedral_type_numbers:
  58. start_idx += 1
  59. if "%FORMAT" in context[start_idx]:
  60. continue
  61. else:
  62. value = list(map(float, context[start_idx].strip().split()))
  63. information.extend(value)
  64. count += len(value)
  65. self.lj_scale_type = information[:self.dihedral_type_numbers]
  66. break
  67. self.processor(context)
  68. def processor(self, context):
  69. '''processor'''
  70. self.h_atom_a = [0] * self.dihedral_numbers
  71. self.h_atom_b = [0] * self.dihedral_numbers
  72. self.h_lj_scale_factor = [0] * self.dihedral_numbers
  73. self.h_cf_scale_factor = [0] * self.dihedral_numbers
  74. nb14_numbers = 0
  75. for idx, val in enumerate(context):
  76. if "%FLAG DIHEDRALS_INC_HYDROGEN" in val:
  77. count = 0
  78. start_idx = idx
  79. information = []
  80. while count < 5 * self.dihedral_with_hydrogen:
  81. start_idx += 1
  82. if "%FORMAT" in context[start_idx]:
  83. continue
  84. else:
  85. value = list(map(int, context[start_idx].strip().split()))
  86. information.extend(value)
  87. count += len(value)
  88. for i in range(self.dihedral_with_hydrogen):
  89. tempa = information[i * 5 + 0]
  90. tempi = information[i * 5 + 1]
  91. tempi2 = information[i * 5 + 2]
  92. tempb = information[i * 5 + 3]
  93. tempi = information[i * 5 + 4]
  94. tempi -= 1
  95. if tempi2 > 0:
  96. self.h_atom_a[nb14_numbers] = tempa / 3
  97. self.h_atom_b[nb14_numbers] = abs(tempb / 3)
  98. self.h_lj_scale_factor[nb14_numbers] = self.lj_scale_type[tempi]
  99. if self.h_lj_scale_factor[nb14_numbers] != 0:
  100. self.h_lj_scale_factor[nb14_numbers] = 1.0 / self.h_lj_scale_factor[nb14_numbers]
  101. self.h_cf_scale_factor[nb14_numbers] = self.cf_scale_type[tempi]
  102. if self.h_cf_scale_factor[nb14_numbers] != 0:
  103. self.h_cf_scale_factor[nb14_numbers] = 1.0 / self.h_cf_scale_factor[nb14_numbers]
  104. nb14_numbers += 1
  105. break
  106. for idx, val in enumerate(context):
  107. if "%FLAG DIHEDRALS_WITHOUT_HYDROGEN" in val:
  108. count = 0
  109. start_idx = idx
  110. information = []
  111. while count < 5 * (self.dihedral_numbers - self.dihedral_with_hydrogen):
  112. start_idx += 1
  113. if "%FORMAT" in context[start_idx]:
  114. continue
  115. else:
  116. value = list(map(int, context[start_idx].strip().split()))
  117. information.extend(value)
  118. count += len(value)
  119. for i in range(self.dihedral_with_hydrogen, self.dihedral_numbers):
  120. tempa = information[(i - self.dihedral_with_hydrogen) * 5 + 0]
  121. tempi = information[(i - self.dihedral_with_hydrogen) * 5 + 1]
  122. tempi2 = information[(i - self.dihedral_with_hydrogen) * 5 + 2]
  123. tempb = information[(i - self.dihedral_with_hydrogen) * 5 + 3]
  124. tempi = information[(i - self.dihedral_with_hydrogen) * 5 + 4]
  125. tempi -= 1
  126. if tempi2 > 0:
  127. self.h_atom_a[nb14_numbers] = tempa / 3
  128. self.h_atom_b[nb14_numbers] = abs(tempb / 3)
  129. self.h_lj_scale_factor[nb14_numbers] = self.lj_scale_type[tempi]
  130. if self.h_lj_scale_factor[nb14_numbers] != 0:
  131. self.h_lj_scale_factor[nb14_numbers] = 1.0 / self.h_lj_scale_factor[nb14_numbers]
  132. self.h_cf_scale_factor[nb14_numbers] = self.cf_scale_type[tempi]
  133. if self.h_cf_scale_factor[nb14_numbers] != 0:
  134. self.h_cf_scale_factor[nb14_numbers] = 1.0 / self.h_cf_scale_factor[nb14_numbers]
  135. nb14_numbers += 1
  136. break
  137. self.nb14_numbers = nb14_numbers