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.

main.py 4.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. '''main'''
  16. import argparse
  17. import time
  18. from src.simulation import Simulation
  19. import mindspore.context as context
  20. from mindspore import Tensor
  21. parser = argparse.ArgumentParser(description='Sponge Controller')
  22. parser.add_argument('--i', type=str, default=None, help='input file')
  23. parser.add_argument('--amber_parm', type=str, default=None, help='paramter file in AMBER type')
  24. parser.add_argument('--c', type=str, default=None, help='initial coordinates file')
  25. parser.add_argument('--r', type=str, default="restrt", help='')
  26. parser.add_argument('--x', type=str, default="mdcrd", help='')
  27. parser.add_argument('--o', type=str, default="mdout", help="")
  28. parser.add_argument('--box', type=str, default="mdbox", help='')
  29. parser.add_argument('--device_id', type=int, default=0, help='')
  30. args_opt = parser.parse_args()
  31. context.set_context(mode=context.GRAPH_MODE, device_target="GPU", device_id=args_opt.device_id, save_graphs=False)
  32. if __name__ == "__main__":
  33. simulation = Simulation(args_opt)
  34. start = time.time()
  35. compiler_time = 0
  36. save_path = args_opt.o
  37. file = open(save_path, 'w')
  38. for steps in range(simulation.md_info.step_limit):
  39. print_step = steps % simulation.ntwx
  40. if steps == simulation.md_info.step_limit - 1:
  41. print_step = 0
  42. temperature, total_potential_energy, sigma_of_bond_ene, sigma_of_angle_ene, sigma_of_dihedral_ene, \
  43. nb14_lj_energy_sum, nb14_cf_energy_sum, LJ_energy_sum, ee_ene, _ = simulation(Tensor(steps), Tensor(print_step))
  44. if steps == 0:
  45. compiler_time = time.time()
  46. if steps % simulation.ntwx == 0 or steps == simulation.md_info.step_limit - 1:
  47. if steps == 0:
  48. print("_steps_ _TEMP_ _TOT_POT_ENE_ _BOND_ENE_ "
  49. "_ANGLE_ENE_ _DIHEDRAL_ENE_ _14LJ_ENE_ _14CF_ENE_ _LJ_ENE_ _CF_PME_ENE_")
  50. file.write("_steps_ _TEMP_ _TOT_POT_ENE_ _BOND_ENE_ "
  51. "_ANGLE_ENE_ _DIHEDRAL_ENE_ _14LJ_ENE_ _14CF_ENE_ _LJ_ENE_ _CF_PME_ENE_\n")
  52. temperature = temperature.asnumpy()
  53. total_potential_energy = total_potential_energy.asnumpy()
  54. print("{:>7.0f} {:>7.3f} {:>11.3f}".format(steps, float(temperature), float(total_potential_energy)),
  55. end=" ")
  56. if simulation.bond.bond_numbers > 0:
  57. sigma_of_bond_ene = sigma_of_bond_ene.asnumpy()
  58. print("{:>10.3f}".format(float(sigma_of_bond_ene)), end=" ")
  59. if simulation.angle.angle_numbers > 0:
  60. sigma_of_angle_ene = sigma_of_angle_ene.asnumpy()
  61. print("{:>11.3f}".format(float(sigma_of_angle_ene)), end=" ")
  62. if simulation.dihedral.dihedral_numbers > 0:
  63. sigma_of_dihedral_ene = sigma_of_dihedral_ene.asnumpy()
  64. print("{:>14.3f}".format(float(sigma_of_dihedral_ene)), end=" ")
  65. if simulation.nb14.nb14_numbers > 0:
  66. nb14_lj_energy_sum = nb14_lj_energy_sum.asnumpy()
  67. nb14_cf_energy_sum = nb14_cf_energy_sum.asnumpy()
  68. print("{:>10.3f} {:>10.3f}".format(float(nb14_lj_energy_sum), float(nb14_cf_energy_sum)), end=" ")
  69. LJ_energy_sum = LJ_energy_sum.asnumpy()
  70. ee_ene = ee_ene.asnumpy()
  71. print("{:>7.3f}".format(float(LJ_energy_sum)), end=" ")
  72. print("{:>12.3f}".format(float(ee_ene)))
  73. if file is not None:
  74. file.write("{:>7.0f} {:>7.3f} {:>11.3f} {:>10.3f} {:>11.3f} {:>14.3f} {:>10.3f} {:>10.3f} {:>7.3f}"
  75. " {:>12.3f}\n".format(steps, float(temperature), float(total_potential_energy),
  76. float(sigma_of_bond_ene), float(sigma_of_angle_ene),
  77. float(sigma_of_dihedral_ene), float(nb14_lj_energy_sum),
  78. float(nb14_cf_energy_sum), float(LJ_energy_sum), float(ee_ene)))
  79. end = time.time()
  80. file.close()
  81. print("Main time(s):", end - start)
  82. print("Main time(s) without compiler:", end - compiler_time)