The rank is calculated in includes/class_dm_user.php, if any information has been set that could affect the rank. The code that does it when you run "Update User Titles and Ranks" in the admincp is in admincp/misc.php. It creates a user datamanger and sets (among other things) the user posts to the same value it already has. That seems like it wouldn't do anything, but the user datamanager code detects that the posts have been set and recalculates rank. I think setting the usergroup should also trigger it to be recalculated, but of course that only would happen if you're using the datamanager to set it (which I'm guessing your script doesn't?). In any case you should just be able to do something like:
Code:
$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT);
$userdm->set_existing($user);
$userdm->set('posts', $user['posts']); // This will activate the rank update
$userdm->save();