How do i enable only certain modules to a user programmatically

Hi Guys,

I have a custom doctype which will create a user and assign the roles programmatically. I would like to extend this customisation by enabling certain module to that particular user. I see that by default all the modules will be enabled and manually going and disabling the modules from user list doesnt make sense to me.

So, I am looking if there is a method or a way to enable only required modules for user after the user is created and roles are assigned programmatically.

Thanks in advance,

Praveen N