def main(): specienames, species, coords, origin, latvecs = readgen("geo.gen") coords /= a0 if (latvecs): latvecs /= a0 tPeriodic = 1 else: latvecs = np.empty((3, 3), dtype=float) tPeriodic = None connection = connect() for iStep in range(NR_STEPS + 1): print("Step %i" % iStep) connection.sendall('POSDATA ') connection.sendall(latvecs) if tPeriodic: connection.sendall(la.inv(latvecs)) else: connection.sendall(np.empty((3, 3), dtype=float)) connection.sendall(np.int32(len(coords))) connection.sendall(coords) connection.sendall('GETFORCE ') # needs work: buf = receive_all(connection, 12) if (buf != 'FORCEREADY '): raise ValueError('Unexpected value of "GETFORCE": "%s"!' % buf) # expecting energy and number of atoms buf = receive_all(connection, 12) unpacked_data = struct.unpack('di', buf) print(unpacked_data) # forces buf = receive_all(connection, len(coords) * 3 * 8) frmat = '%i' % (3 * len(coords)) frmat += 'd' unpacked_data = struct.unpack(frmat, buf) print(unpacked_data) # stress x lattive volume buf = receive_all(connection, 9 * 8) unpacked_data = struct.unpack('9d', buf) print(unpacked_data) # dummy '0' at the end of the data buf = receive_all(connection, 4) unpacked_data = struct.unpack('i', buf) print(unpacked_data) connection.shutdown(socket.SHUT_RDWR) connection.close()
def main(): specienames, species, coords, origin, latvecs = readgen("diamond.gen") coords /= a0 latvecs /= a0 connection = connect() for iStep in range(NR_STEPS): print("Step %i" % iStep) connection.sendall('POSDATA ') connection.sendall(latvecs) connection.sendall(la.inv(latvecs)) connection.sendall(np.int32(len(coords))) connection.sendall(coords) connection.sendall('GETFORCE ') # needs work: buf = receive_all(connection, 12) if (buf != 'FORCEREADY '): raise ValueError('Unexpected value of "GETFORCE": "%s"!' % buf) # expecting energy and number of atoms buf = receive_all(connection, 12) unpacked_data = struct.unpack('di', buf) print(unpacked_data) # forces buf = receive_all(connection, len(coords) * 3 * 8) frmat = '%i' % (3 * len(coords)) frmat += 'd' unpacked_data = struct.unpack(frmat, buf) print(unpacked_data) # stress x lattive volume buf = receive_all(connection, 9 * 8) unpacked_data = struct.unpack('9d', buf) print(unpacked_data) # dummy '0' at the end of the data buf = receive_all(connection, 4) unpacked_data = struct.unpack('i', buf) print(unpacked_data) print("Requesting clean shutdown of DFTB+") connection.sendall('EXIT ') time.sleep(2) connection.shutdown(socket.SHUT_RDWR) connection.close()