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 3.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. from src.mdnn import Mdnn, TransCrdToCV
  20. import mindspore.context as context
  21. from mindspore import Tensor
  22. from mindspore import load_checkpoint
  23. parser = argparse.ArgumentParser(description='SPONGE Controller')
  24. parser.add_argument('--i', type=str, default=None, help='Input file')
  25. parser.add_argument('--amber_parm', type=str, default=None, help='Paramter file in AMBER type')
  26. parser.add_argument('--c', type=str, default=None, help='Initial coordinates file')
  27. parser.add_argument('--r', type=str, default="restrt", help='')
  28. parser.add_argument('--x', type=str, default="mdcrd", help='')
  29. parser.add_argument('--o', type=str, default="mdout", help='Output file')
  30. parser.add_argument('--box', type=str, default="mdbox", help='')
  31. parser.add_argument('--device_id', type=int, default=0, help='GPU device id')
  32. parser.add_argument('--u', type=bool, default=False, help='If use mdnn to update the atom charge')
  33. parser.add_argument('--checkpoint', type=str, default="", help='Checkpoint file')
  34. args_opt = parser.parse_args()
  35. context.set_context(mode=context.GRAPH_MODE, device_target="GPU", device_id=args_opt.device_id, save_graphs=False)
  36. if __name__ == "__main__":
  37. simulation = Simulation(args_opt)
  38. if args_opt.u and args_opt.checkpoint:
  39. net = Mdnn()
  40. load_checkpoint(args_opt.checkpoint, net=net)
  41. transcrd = TransCrdToCV(simulation)
  42. start = time.time()
  43. compiler_time = 0
  44. save_path = args_opt.o
  45. simulation.Main_Initial()
  46. for steps in range(simulation.md_info.step_limit):
  47. print_step = steps % simulation.ntwx
  48. if steps == simulation.md_info.step_limit - 1:
  49. print_step = 0
  50. temperature, total_potential_energy, sigma_of_bond_ene, sigma_of_angle_ene, sigma_of_dihedral_ene, \
  51. nb14_lj_energy_sum, nb14_cf_energy_sum, LJ_energy_sum, ee_ene, _ = simulation(Tensor(steps), Tensor(print_step))
  52. if steps == 0:
  53. compiler_time = time.time()
  54. if steps % simulation.ntwx == 0 or steps == simulation.md_info.step_limit - 1:
  55. simulation.Main_Print(steps, temperature, total_potential_energy, sigma_of_bond_ene, sigma_of_angle_ene,
  56. sigma_of_dihedral_ene, nb14_lj_energy_sum, nb14_cf_energy_sum, LJ_energy_sum, ee_ene)
  57. if args_opt.u and args_opt.checkpoint and steps % (4 * simulation.ntwx) == 0:
  58. print("Update charge!")
  59. inputs = transcrd(Tensor(simulation.crd), Tensor(simulation.last_crd))
  60. t_charge = net(inputs)
  61. simulation.charge = transcrd.updatecharge(t_charge)
  62. end = time.time()
  63. print("Main time(s):", end - start)
  64. print("Main time(s) without compiler:", end - compiler_time)
  65. simulation.Main_Destroy()