Section 39D. If the parents of an unmarried minor child are divorced, married but living apart, under a temporary order or judgment of separate support, or if either or both parents are deceased, or if said unmarried minor child was born out of wedlock whose paternity has been adjudicated by a court of competent jurisdiction or whose father has signed an acknowledgement of paternity, and the parents do not reside together, the grandparents of such minor child may be granted reasonable visitation rights to the minor child during his minority by the probate and family court department of the trial court upon a written finding that such visitation rights would be in the best interest of the said minor child; provided, however, that such adjudication of paternity or acknowledgment of paternity shall not be required in order to proceed under this section where maternal grandparents are seeking such visitation rights. No such visitation rights shall be granted if said minor child has been adopted by a person other than a stepparent of such child and any visitation rights granted pursuant to this section prior to such adoption of the said minor child shall be terminated upon such adoption without any further action of the court.
A petition for grandparents visitation authorized under this section shall, where applicable, be filed in the county within the commonwealth in which the divorce or separate support complaint or the complaint to establish paternity was filed. If the divorce, separate support or paternity judgment was entered without the commonwealth but the child presently resides within the commonwealth, said petition may be filed in the county where the child resides.