I'm using the *Peptides* package in R to calculate the mass of peptides with the mw() method. The thing is that I want to calculate them for different pH values, and thus I wrote this little function to take the pH value into account according this image:

[![Enter image description here](https://i.stack.imgur.com/iA96t.jpg)](https://i.stack.imgur.com/iA96t.jpg)

My code is this:

```
phmw = function(pept_seq , unimod_location, pH ){

  monoisotopic_hydrogen_mass = 1.00794

  if(pH < 7){

    # mol_weight = mol_weight_of_peptide + mol_weight_of_Hydrogen
    mol_weight = mw(pept_seq, monoisotopic = T) + monoisotopic_hydrogen_mass

  }else if(pH > 7){

    # mol_weight = mol_weight_of_peptide - mol_weight_of_Hydrogen
    mol_weight = mw(pept_seq, monoisotopic = T) - monoisotopic_hydrogen_mass

  }else if(pH == 7){

    # mol_weight = mol_weight_of_peptide 
    mol_weight = mw(pept_seq, monoisotopic = T) 
  }

  return(mol_weight)

}

```

Do you think that this approach is correct or not?