Ab initio study of cationic polymeric membranes in water and methanol