A theoretical method to determine atomic pseudopotentials for electronic structure calculations of molecules and solids