Oscar,
It's not extremely complicated, but one doesn't generally have sufficient information to be able to do it correctly.
Assuming that the octet rule should apply to the molecule, you need 3 of the following four pieces of information and then you can calculate the last :
- formal charge
- number of attached hydrogens
- heavy-atom valence (sum of all bond orders to non-hydrogen atoms)
- number of radical electrons
Typical chemistry files (i.e. SMILES and MOL) assume that everything is specified except the number of attached hydrogens.
Best,
-greg