def send_forces(self): self.s.send_header(Message("forceready")) self.s.send_data(np.array([self.e])) self.s.send_data(np.array([self.natom])) self.s.send_data(self.gpos.ravel()) self.s.send_data(self.vtens.ravel()) self.s.send_data(np.array([np.int32(9)])) self.s.send_data("YAFF Done") self.hasdata = False
def run(self): # Run indefinitely (until i-PI sends exit message) while True: with timer.section("WAITHEADER"): # log("WAITHEADER %s" % datetime.now()) header = self.s.await_header() # log("GOTHEADER %s" % datetime.now()) if header == Message("status"): if not self.isinit: self.s.send_header(Message("needinit")) elif self.hasdata: self.s.send_header(Message("havedata")) else: self.s.send_header(Message("ready")) elif header == Message("init"): # ibead = np.fromstring(self.s.await_data(L_INT), np.int32)[0] # len_init = np.fromstring(self.s.await_data(L_INT), np.int32)[0] # init = self.s.await_data(len_init * L_CHAR) if log.do_high: with log.section(self.log_name): # log( "YAFF driver initialized for pid %s (bead %d - %s)" % (os.getpid(), ibead, init) ) log("INIT %s" % datetime.now()) self.isinit = True elif header == Message("posdata"): with timer.section("RECVPOS"), log.section(self.log_name): self.receive_pos() log("RECV %-12s %s" % ("POS", datetime.now())) with timer.section("COMPUTE"): self.compute() elif header == Message("getforce"): with timer.section("SENDFORCE"), log.section(self.log_name): self.send_forces() log("SEND %-12s %s" % ("FORCE", datetime.now())) elif header == Message("exit"): if log.do_high: with log.section(self.log_name): # log('i-PI finished, stopping Yaff driver') log("EXIT %s" % datetime.now()) break else: raise NotImplementedError("Received unknown message %s" % header)