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.

angle.py 6.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. '''Angle'''
  16. class Angle:
  17. '''Angle'''
  18. def __init__(self, controller):
  19. if controller.amber_parm is not None:
  20. file_path = controller.amber_parm
  21. self.read_information_from_amberfile(file_path)
  22. def read_information_from_amberfile(self, file_path):
  23. '''read amber file'''
  24. file = open(file_path, 'r')
  25. context = file.readlines()
  26. file.close()
  27. for idx, val in enumerate(context):
  28. if idx < len(context) - 1:
  29. if "%FLAG POINTERS" in val + context[idx + 1] and "%FORMAT(10I8)" in val + context[idx + 1]:
  30. start_idx = idx + 2
  31. count = 0
  32. value = list(map(int, context[start_idx].strip().split()))
  33. self.angle_with_H_numbers = value[4]
  34. self.angle_without_H_numbers = value[5]
  35. self.angle_numbers = self.angle_with_H_numbers + self.angle_without_H_numbers
  36. # print(self.angle_numbers)
  37. information = []
  38. information.extend(value)
  39. while count < 15:
  40. start_idx += 1
  41. value = list(map(int, context[start_idx].strip().split()))
  42. information.extend(value)
  43. count += len(value)
  44. self.angle_type_numbers = information[16]
  45. print("angle type numbers ", self.angle_type_numbers)
  46. break
  47. self.h_atom_a = [0] * self.angle_numbers
  48. self.h_atom_b = [0] * self.angle_numbers
  49. self.h_atom_c = [0] * self.angle_numbers
  50. self.h_type = [0] * self.angle_numbers
  51. angle_count = 0
  52. for idx, val in enumerate(context):
  53. if "%FLAG ANGLES_INC_HYDROGEN" in val:
  54. count = 0
  55. start_idx = idx
  56. information = []
  57. while count < 4 * self.angle_with_H_numbers:
  58. start_idx += 1
  59. if "%FORMAT" in context[start_idx]:
  60. continue
  61. else:
  62. value = list(map(int, context[start_idx].strip().split()))
  63. information.extend(value)
  64. count += len(value)
  65. for _ in range(self.angle_with_H_numbers):
  66. self.h_atom_a[angle_count] = information[angle_count * 4 + 0] / 3
  67. self.h_atom_b[angle_count] = information[angle_count * 4 + 1] / 3
  68. self.h_atom_c[angle_count] = information[angle_count * 4 + 2] / 3
  69. self.h_type[angle_count] = information[angle_count * 4 + 3] - 1
  70. angle_count += 1
  71. break
  72. for idx, val in enumerate(context):
  73. if "%FLAG ANGLES_WITHOUT_HYDROGEN" in val:
  74. count = 0
  75. start_idx = idx
  76. information = []
  77. while count < 4 * self.angle_without_H_numbers:
  78. start_idx += 1
  79. if "%FORMAT" in context[start_idx]:
  80. continue
  81. else:
  82. value = list(map(int, context[start_idx].strip().split()))
  83. information.extend(value)
  84. count += len(value)
  85. for _ in range(self.angle_without_H_numbers):
  86. self.h_atom_a[angle_count] = information[(angle_count - self.angle_with_H_numbers) * 4 + 0] / 3
  87. self.h_atom_b[angle_count] = information[(angle_count - self.angle_with_H_numbers) * 4 + 1] / 3
  88. self.h_atom_c[angle_count] = information[(angle_count - self.angle_with_H_numbers) * 4 + 2] / 3
  89. self.h_type[angle_count] = information[(angle_count - self.angle_with_H_numbers) * 4 + 3] - 1
  90. angle_count += 1
  91. break
  92. self.processor(context, angle_count)
  93. def processor(self, context, angle_count):
  94. ''' processor '''
  95. self.type_k = [0] * self.angle_type_numbers
  96. for idx, val in enumerate(context):
  97. if "%FLAG ANGLE_FORCE_CONSTANT" in val:
  98. count = 0
  99. start_idx = idx
  100. information = []
  101. while count < self.angle_type_numbers:
  102. start_idx += 1
  103. if "%FORMAT" in context[start_idx]:
  104. continue
  105. else:
  106. # print(start_idx)
  107. value = list(map(float, context[start_idx].strip().split()))
  108. information.extend(value)
  109. count += len(value)
  110. self.type_k = information[:self.angle_type_numbers]
  111. break
  112. self.type_theta0 = [0] * self.angle_type_numbers
  113. for idx, val in enumerate(context):
  114. if "%FLAG ANGLE_EQUIL_VALUE" in val:
  115. count = 0
  116. start_idx = idx
  117. information = []
  118. while count < self.angle_type_numbers:
  119. start_idx += 1
  120. if "%FORMAT" in context[start_idx]:
  121. continue
  122. else:
  123. value = list(map(float, context[start_idx].strip().split()))
  124. information.extend(value)
  125. count += len(value)
  126. self.type_theta0 = information[:self.angle_type_numbers]
  127. break
  128. if self.angle_numbers != angle_count:
  129. print("angle count %d != angle_number %d ", angle_count, self.angle_numbers)
  130. self.h_angle_k = []
  131. self.h_angle_theta0 = []
  132. for i in range(self.angle_numbers):
  133. self.h_angle_k.append(self.type_k[self.h_type[i]])
  134. self.h_angle_theta0.append(self.type_theta0[self.h_type[i]])