A general formalism of deriving the pair potential of polymer chains for arbitrary interaction potentials between isolated chain segments at and close to the theta-point